\附加在JSON响应中。我应该如何删除它

时间:2022-10-14 15:15:36
{
  "content": "{\"text\":\"Executing NodeDatasetFileOrDirectoryCSV : 1\",\"id\":1,\"name\":\"CSV\",\"type\":\"text\"}"
}

\ tag is getting appended after everything.

所有内容都会附加\ tag。

I want to access the type field. But i am not able to even after content.type because of the \ appended after every element. How to remove this ?

我想访问类型字段。但是我甚至无法在content.type之后因为在每个元素之后附加了\。如何删除?

2 个解决方案

#1


2  

You're response is coming down as a valid JSON object, but the content property holds a value that is a JSON string, not a JSON object. You can either fix it on your server-side however you are constructing your response, or you can use JSON.parse to parse the content JSON string into a full-fledged object in JavaScript after you get your response.

您的响应将作为有效的JSON对象发布,但content属性包含的值是JSON字符串,而不是JSON对象。您可以在服务器端修复它,但是要构建响应,或者在获得响应后,可以使用JSON.parse将内容JSON字符串解析为JavaScript中的完整对象。

The latter would be something like this:

后者将是这样的:

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

#2


0  

Use JSON.parse() to get the JSON object from the string and then get the values using keys.

使用JSON.parse()从字符串中获取JSON对象,然后使用键获取值。

#1


2  

You're response is coming down as a valid JSON object, but the content property holds a value that is a JSON string, not a JSON object. You can either fix it on your server-side however you are constructing your response, or you can use JSON.parse to parse the content JSON string into a full-fledged object in JavaScript after you get your response.

您的响应将作为有效的JSON对象发布,但content属性包含的值是JSON字符串,而不是JSON对象。您可以在服务器端修复它,但是要构建响应,或者在获得响应后,可以使用JSON.parse将内容JSON字符串解析为JavaScript中的完整对象。

The latter would be something like this:

后者将是这样的:

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

#2


0  

Use JSON.parse() to get the JSON object from the string and then get the values using keys.

使用JSON.parse()从字符串中获取JSON对象,然后使用键获取值。