[英]what is the proper way to implement this JSON.parse?
我需要使用js中内置的普通香草JSON.parse。 这是我使用xhr调用的服务返回的xmlhttp.responseText:
"[{\"Id\":1071,\"Title\":\"Scheduled Maintenance\",\"Summary\":\"Site will be unavailable Sunday, August 7th between 9:00AM and 10:00AM MST.\",\"Severity\":\"Informational\",\"ApplicationsImpacted\":[1068],\"IsPubliclyViewable\":true,\"IsDismissable\":true}]"
JSON.parse()不会将此字符串转换为对象。 但是,如果我这样编写js,JSON.parse()会将此字符串转换为对象:
JSON.parse(JSON.parse(xmlhttp.responseText))
这似乎是一个hack。 您能推荐一种更干净的方法将此字符串转换为对象吗?
只需删除字符串开头和结尾的多余引号(“),它就可以正常工作。
JSON.parse("[{\"Id\":1071,\"Title\":\"Scheduled Maintenance\",\"Summary\":\"Site will be unavailable Sunday, August 7th between 9:00AM and 10:00AM MST.\",\"Severity\":\"Informational\",\"ApplicationsImpacted\":[1068],\"IsPubliclyViewable\":true,\"IsDismissable\":true}]")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.