-1

我在使用 ajax/json 时遇到问题

PHPjson_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
}
4

1 回答 1

0

您的mex变量不正确;

或者

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

因为,JSON 是正确的。JSFiddle

于 2013-08-16T11:47:11.637 回答