簡體   English   中英

實現此JSON.parse的正確方法是什么?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM