我正在使用javascript。以下是jax响应的对象,
artifacts
我的代码是,
{"readyState":4,"responseText":"\r\nsuccess","status":200,"statusText":"OK"}
现在我想从这个对象中获取responseText。任何帮助非常感谢!
答案 0 :(得分:3)
而不是JSON.stringify
您需要JSON.parse
parse
会将传入的 JSON 字符串解析为相应的 Javascript 对象。 stringify
是相反的操作 - 将Javascript对象转换为 JSON 有效字符串。
答案 1 :(得分:0)
// When your server response comes with full qualified parsed JSON, it may access without any parsing.
var data, resp;
data = {"readyState":4,"responseText":"\r\nsuccess","status":200,"statusText":"OK"};
resp = data.responseText;
console.log("Response as JSON object >",resp);
// When your server response comes with JSON as string, then you require to first parse then you may allows to access.
data = '{\"readyState\":4,\"responseText\":\"\\r\\nsuccess\",\"status\":200,\"statusText\":\"OK\"}';
data = JSON.parse(data);
resp = data.responseText;
console.log("Response after parsing JSON >",resp);