简体   繁体   English

JSON.parse错误

[英]JSON.parse error

I am trying to parse a result I get through a websocket. 我正在尝试解析通过网络套接字获得的结果。

sock.onmessage = function(e) {
    log(e.data);
}

function log(m) {       
    var obj = JSON.parse(m);
}

But I get the error 但是我得到了错误

SyntaxError: JSON.parse: unexpected character

On the server it says in python 在服务器上用python表示

def broadcast(self):

  response = urllib2.urlopen('http://localhost:8001/json?as_text=1')
  data = response.read();

  for c in self.clients:
     c.sendMessage(data)

May be you have to do something like that 可能您必须要做类似的事情

data= JSON.stringify(response) 数据= JSON.stringify(响应)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM