[英]how to get value from json response object
i want to get amount value from following json response how to get 我想从以下json响应中获取金额值
Object {readyState: 4, responseText: "{"amount":1231,"firstName":"dfsdf","lastName":"lasernmae","email":"vijaitest@gmail.com"}", status: 200, statusText: "OK"}
complete: function(response) { var jsonObject = $.parseJSON(response); console.debug(jsonObject.responseText.amount); }
for above coding i am getting Uncaught SyntaxError: Unexpected token o. 对于上面的编码,我得到了Uncaught SyntaxError:意外的令牌o。
var data = '{"readyState": 4, "responseText": {"amount":1231,"firstName":"dfsdf","lastName":"lasernmae","email":"vijaitest@gmail.com"}, "status": 200, "statusText": "OK"}';
var jsonObject = $.parseJSON(data);
console.debug(jsonObject.responseText.amount);
if you have responseText as String you can use following code: 如果将responseText作为String,则可以使用以下代码:
var resT = $.parseJSON(response.responseText);
console.debug(resT.amount);
Assuming your object has the variable name of data. 假设您的对象具有data的变量名。 Just do..
做就是了..
var amount = data.responseText.amount;
If you are getting that response from a server, and still need to parse it. 如果您正在从服务器获得该响应,则仍然需要解析它。
var data = JSON.parse(theObjectsVariableNameHere);
var amount = data.responseText.amount;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.