好的,在我的 python 代码中。我有这个
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
}
似乎 parse 方法不起作用。没有弹出警报。如果我删除 parse line 并把它比 alert 弹出,如果我只是更改 alert 并继续解析它仍然没有做任何事情;
alert(m.data) // this prints out {"here": "aaa", "there": "bbb"}
所以我知道为什么它解析不正确。我假设它与引号有关。我想我又遇到了他们的麻烦。
更新
请看下面我的回答,我解决了这个问题。