解析JSON时无效的字符

时间:2018-01-22 11:14:33

标签: javascript json typescript

我已将对象存储在本地存储中,但在解析该值时出错。我不知道错过了什么。我无法更改值,因为它来自数据库。我需要一种正确的方法来处理此错误,而不是更改字符串值。



Console.log(JSON.parse("{\"Id\":1,\"MenuType\":\"A00\",\"MenuName\":\"Search\",\"UserDetail\":{\"UserName\":\"rajendranra\"},\"cocFunctions\":[{\"Id\":1,\"FunctionName\":\"View COC\",\"Description\":\"View COC information for a version\",\"IsDefault\":true},{\"Id\":3,\"FunctionName\":\"View order by FYON\",\"Description\":\"View order by FYON\",\"IsDefault\":true},{\"Id\":5,\"FunctionName\":\"Delete COC\",\"Description\":\"Delete existing COC\",\"IsDefault\":false},{\"Id\":7,\"FunctionName\":\"Set and remove COC duplicate\",\"Description\":\"Set and remove COC duplicate\",\"IsDefault\":false},{\"Id\":11,\"FunctionName\":\"Handle COC information for a current version\",\"Description\":\"Handle COC information for a current version\",\"IsDefault\":false},{\"Id\":12,\"FunctionName\":\"Simulate COC\",\"Description\":\"Simulate COC\",\"IsDefault\":false},{\"Id\":15,\"FunctionName\":\"Release or Hold COC\",\"Description\":\"Release or Hold COC\",\"IsDefault\":false},{\"Id\":20,\"FunctionName\":\"Create vehicle on temporary Stop/ FYON\",\"Description\":\"Create vehicle on temporary Stop/ FYON\",\"IsDefault\":false}]}")




2 个答案:

答案 0 :(得分:1)

  最后错过了

) ..!

console.log(JSON.parse("{\"Id\":1,\"MenuType\":\"A00\",\"MenuName\":\"Search\",\"UserDetail\":{\"UserName\":\"rajendranra\"},\"cocFunctions\":[{\"Id\":1,\"FunctionName\":\"View COC\",\"Description\":\"View COC information for a version\",\"IsDefault\":true},{\"Id\":3,\"FunctionName\":\"View order by FYON\",\"Description\":\"View order by FYON\",\"IsDefault\":true},{\"Id\":5,\"FunctionName\":\"Delete COC\",\"Description\":\"Delete existing COC\",\"IsDefault\":false},{\"Id\":7,\"FunctionName\":\"Set and remove COC duplicate\",\"Description\":\"Set and remove COC duplicate\",\"IsDefault\":false},{\"Id\":11,\"FunctionName\":\"Handle COC information for a current version\",\"Description\":\"Handle COC information for a current version\",\"IsDefault\":false},{\"Id\":12,\"FunctionName\":\"Simulate COC\",\"Description\":\"Simulate COC\",\"IsDefault\":false},{\"Id\":15,\"FunctionName\":\"Release or Hold COC\",\"Description\":\"Release or Hold COC\",\"IsDefault\":false},{\"Id\":20,\"FunctionName\":\"Create vehicle on temporary Stop/ FYON\",\"Description\":\"Create vehicle on temporary Stop/ FYON\",\"IsDefault\":false}]}"));

答案 1 :(得分:1)

Console.log(JSON.parse(中有两个开括号,但在该行的末尾,只有一个右括号)。你需要添加另一个。

此外,您正在使用Console。那不会奏效。它应该是console