Json 结果获取值

Json result get values

本文关键字:获取 结果 Json      更新时间:2023-09-26

从控制器返回 Json,在函数中我得到一个包含

{
    "readyState":4,
    "responseText":"{'"Success'":0,'"Failed'":0}",
    "responseJSON":{
        "Success":0,
        "Failed":0
    },
    "status":200,
    "statusText":"OK"
}

如何获取成功和失败值?

数据。Successand JSON.parse(data) 不起作用

你不需要解析它,因为它已经是一个对象:

var obj = {"readyState":4,"responseText":"{'"Success'":0,'"Failed'":0}","responseJSON":{"Success":0,"Failed":0},"status":200,"statusText":"OK"};
var failed = obj.responseJSON.Failed;
var success = obj.responseJSON.Success;
var json_data = '{"readyState":4,"responseText":"{'"Success'":0,'"Failed'":0}",
 "responseJSON":{"Success":0,"Failed":0},"status":200,"statusText":"OK"}';
var obj = JSON.parse(json_data);

alert(obj.responseJSON.Success);  // for success that in responseJSON
alert(obj.responseJSON.Failed);

谢谢:)