我正在尝试将我的字符串解析为JSON对象,但是它不起作用。调试代码时出现语法错误。这是我要解析的字符串:
var listString = "{ title: 'MySchema'," + "root: {id:'" + headID + "',"
+ "title:'" + topHead[0].Designation + "'," + "subtitle:'" + headName + "',";
liststring = liststring + "{ id: '" + head + "'," + "title: '" + childs[cnt].Designation + "'," + "subtitle: '" + title + "'," + "type: '" + childs[cnt].Typav + "'";
liststring = getChildNodes(tasksEntries, head, liststring); liststring = liststring + "},";}liststring = liststring + "]}}";} listString = childliststring;
$ .parseJSON(listString);
我没有得到任何JSON对象作为回报。有什么想法吗?
最佳答案
jour JSON字符串应为'{“ key”:“ value”}'格式JSON.parse("{id:'1'}");
语法错误:意外的令牌我JSON.parse("{'id':'1'}");
SyntaxError:意外令牌'JSON.parse('{"id":"1"}');
对象{id:“ 1”}JSON.parse('{"id":1}');
对象{id:1}
关于javascript - 将字符串类型解析为JSON对象时出错,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21848249/