簡體   English   中英

\\附加在JSON響應中。 我該如何刪除

[英]\ getting appended in the JSON response. How should i remove this

{
  "content": "{\"text\":\"Executing NodeDatasetFileOrDirectoryCSV : 1\",\"id\":1,\"name\":\"CSV\",\"type\":\"text\"}"
}

\\標記將附加在所有內容之后。

我想訪問類型字段。 但是由於在每個元素后附加了\\所以我什至不能在content.type之后。 如何刪除呢?

您的響應正在下降,因為它是有效的JSON對象,但是content屬性包含的值是JSON字符串 ,而不是JSON對象。 您既可以在服務器端修復它,也可以構建響應,也可以使用JSON.parse在響應后將content JSON字符串解析為JavaScript中的完整對象。

后者將是這樣的:

var response = {"content": "{\"text\":\"Executing NodeDatasetFileOrDirectoryCSV : 1\",\"id\":1,\"name\":\"CSV\",\"type\":\"text\"}" };
response.content = JSON.parse(response.content);
console.log(response.content.type);

使用JSON.parse()從字符串獲取JSON對象,然后使用鍵獲取值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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