JSON.parse:JSON数据的第1行第2列中的预期属性名称或“}" [英] JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data

查看:54
本文介绍了JSON.parse:JSON数据的第1行第2列中的预期属性名称或“}"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的JSON字符串为:

I am getting my JSON string as:

newStr = { total:"1", page:"1", records:"2", rows: [<li>a</li><li>b</li>] }.
jQuery("#list").addJSONData(JSON.parse(newStr)); 

推荐答案

您正在尝试解析不是字符串的内容.这将隐式调用对象上的toString,您将获得字符串[object Object],它是无效的JSON.

You are trying to parse something that is not a string. This will implicitly call toString on the object, and you get the string [object Object], which is not valid JSON.

解析字符串:

newStr = '{"total":"1","page":"1","records":"2","rows":["<li>a</li>", "<li>b</li>"]}';
jQuery("#list").addJSONData(JSON.parse(newStr)); 

或使用对象:

newStr = { total:"1", page:"1", records:"2", rows: ["<li>a</li>", "<li>b</li>"] };
jQuery("#list").addJSONData(newStr); 

这篇关于JSON.parse:JSON数据的第1行第2列中的预期属性名称或“}"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆