gpt4 book ai didi

javascript - 将字符串类型解析为 JSON 对象时出错

转载 作者:行者123 更新时间:2023-11-28 08:31:13 25 4
gpt4 key购买 nike

我正在尝试将字符串解析为 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'}");

语法错误:意外的标记 i

JSON.parse("{'id':'1'}");

语法错误:意外的标记'

JSON.parse('{"id":"1"}');

对象 {id: "1"}

JSON.parse('{"id":1}');

对象 {id: 1}

关于javascript - 将字符串类型解析为 JSON 对象时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21848249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com