通过 JavaScript 解析从 AJAX 请求得到的 JSON 响应
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14478127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Parse JSON response got from AJAX request through JavaScript
提问by Milo?
I'm geting a JSON response with an AJAX request through JavaScript.
我正在通过 JavaScript 获得带有 AJAX 请求的 JSON 响应。
Here is the response:
这是回应:
{"responseCode":400,"errors":false,"submitted":false,"content":"some content","notice":""}
My Goal is to get the content:
我的目标是获取内容:
"some content"
The json variable is the data in my case. So, I have tried with:
在我的例子中,json 变量是数据。所以,我尝试过:
data.content
But I am geting an empty string.
但我得到一个空字符串。
Any idea on how to access the string?
关于如何访问字符串的任何想法?
Thank you in advance.
先感谢您。
回答by Dejo
Did you first parse json ?
你首先解析 json 吗?
var data = JSON.parse(json);
than read data.content
比阅读 data.content

