好的在我的python代码中。我有这个无法解析从频道发送的json
foo = "aaa"; //foo and bar are variables that change, just an example here
bar = "bbb";
json = {"here": foo, "there": bar} //also tried single quotes
message = simplejson.dumps(json) //also tried just json instead of simplejson
channel.send_message(user_id(), message)
在javascript中
onMessage = function(m) {
var a = JSON.parse(m.data);
alert(a.here); // foo should pop up but it doesnt
}
好像解析方法不起作用。没有弹出的警报。如果我删除解析行,并将此提示弹出,那么如果我只是更改警报并继续解析,它仍然会做任何事情;
alert(m.data) // this prints out {"here": "aaa", "there": "bbb"}
所以idk为什么不解析正确。我假设它与报价有关。我想我再次遇到麻烦了。
UPDATE
请看看下面我的回答,我解决了这个问题。
你现在可以'导入JSON',而不是简单的JSON应用引擎FYI。 – 2013-02-16 15:17:51
是的,我也试过。没有工作。 – btevfik 2013-02-16 15:37:14
您是否尝试过在''var a = JSON.parse(m.data)''中编写数据的硬编码,从而驳斥您对JSON.parse无法正常工作的担忧。 – sotapme 2013-02-16 16:32:29