[{"eqsn":"开卷线","Hour":"07:10:00","datetime":"2013-09-23","eqid":"2013092317151240038233190"},{"eqsn":"开卷线","Hour":"07:10:00","datetime":"2013-09-16","eqid":"2013092317200317045171826"},{"eqsn":"开卷线","Hour":"07:10:00","datetime":"2013-09-15","eqid":"2013092317203377322080592"},{"eqsn":"开卷线","Hour":"00:50:00","datetime":"2013-09-17","eqid":"2013092317332622322664873"},{"eqsn":"开卷线","Hour":"06:00:00","datetime":"2013-09-18","eqid":"2013092317351996072634767"}]
这个我循环拼出来的字符串,各位客官帮我看看哪里错了 ,为什么会报这种奇怪的错误!
5 个解决方案
var obj = $.parseJSON('{"name":"John"}');
alert( obj.name === "John" );
var xx = '[{ "eqsn": "开卷线", "Hour": "07:10:00", "datetime": "2013-09-23", "eqid": "2013092317151240038233190" }, { "eqsn": "开卷线", "Hour": "07:10:00", "datetime": "2013-09-16", "eqid": "2013092317200317045171826" }, { "eqsn": "开卷线", "Hour": "07:10:00", "datetime": "2013-09-15", "eqid": "2013092317203377322080592" }, { "eqsn": "开卷线", "Hour": "00:50:00", "datetime": "2013-09-17", "eqid": "2013092317332622322664873" }, { "eqsn": "开卷线", "Hour": "06:00:00", "datetime": "2013-09-18", "eqid": "2013092317351996072634767"}]';
var ChangeJson = $.parseJSON(xx);
有引用jquery?
或者
function StrToJson(str) {
var json = (new Function("return " + str))();
return json;
}
用这个转试试 我经常用
引用jquery
var strJson = '{"XXOOSS": [{"eqsn":"开卷线","Hour":"07:10:00","datetime":"2013-09-23","eqid":"2013092317151240038233190"},{"eqsn":"开卷线2","Hour":"07:10:00","datetime":"2013-09-16","eqid":"2013092317200317045171826"},{"eqsn":"开卷线","Hour":"07:10:00","datetime":"2013-09-15","eqid":"2013092317203377322080592"},{"eqsn":"开卷线","Hour":"00:50:00","datetime":"2013-09-17","eqid":"2013092317332622322664873"},{"eqsn":"开卷线","Hour":"06:00:00","datetime":"2013-09-18","eqid":"2013092317351996072634767"}]}';
var obj = jQuery.parseJSON(strJson);
//取值
alert(obj.XXOOSS[0].eqsn);