json_encode()生成的json字符串上的json意外标记错误

时间:2013-08-16 11:28:35

标签: javascript ajax json

我遇到了ajax / json的问题

Php json_encode()生成了这个json代码:

[{"createdDate":"2013-08-16 13:23:35","body":"kpk"},
{"createdDate":"2013-08-16 13:20:18","body":"iji"},
{"createdDate":"2013-08-16 13:17:34","body":"kp"},
{"createdDate":"2013-08-16 13:17:16","body":"kp"},
{"createdDate":"2013-08-16 13:15:11","body":"koml"},
{"createdDate":"2013-08-16 13:14:08","body":"lplpp,"},
{"createdDate":"2013-08-16 13:13:59","body":"lplpp,"},
{"createdDate":"2013-08-16 13:10:51","body":"mpmkp"},
{"createdDate":"2013-08-16 13:10:29","body":"ook"},
{"createdDate":"2013-08-16 13:07:48","body":"oomoloo"}]

但我不断收到意外的令牌错误,有人可以向我解释原因吗?

当我尝试解析json字符串时抛出错误 通过以下方式:

function ajax_callback(mex)  
{
   mexx = JSON.parse(mex); 
   //other stuff
}

1 个答案:

答案 0 :(得分:0)

您的mex变量不正确;

OR

您没有正确使用变量mexx,请注意mexx将导致数组生成,因此您必须像这样使用它:mexx[0].body

因为,JSON是正确的。 JSFiddle