[英]Json Data extraction
I have a webservice and it returns json data like this.. 我有一个网络服务,它返回像这样的json数据。
{"d":"{\"RES\":[],\"STAT\":\"FAIL\",\"SID\":\"0\"}"}
how i can i read the STAT=FAIL from this. 我如何从中读取STAT = FAIL。 I wrote service in c#.
我用C#编写服务。
my script is 我的剧本是
$.ajax({
type: "POST",
url: "http://localhost/EMRDMSService/Service.asmx/User_Login",
data: "{lg:" + JSON.stringify(GetLogDet) + "}",
// url: "http://localhost/EMRDMSService/Service.asmx/Permission_List",
// data: "{userid:" + JSON.stringify(GetLogDet) + "}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
console.log(r.d.STAT);
}
});
But the rdSTAT is undefined
? 但是rdSTAT是
undefined
吗? Can anybody help me with this? 有人可以帮我吗?
As said in some of the comments, {"d":"{\\"RES\\":[],\\"STAT\\":\\"FAIL\\",\\"SID\\":\\"0\\"}"}
isn't correct JSON. 如某些评论中所述,
{"d":"{\\"RES\\":[],\\"STAT\\":\\"FAIL\\",\\"SID\\":\\"0\\"}"}
不是正确的JSON。 However, if you can't update the webservice, you could try this in your success
callback: 但是,如果您无法更新Web服务,则可以在
success
回调中尝试以下操作:
var d = JSON.parse(r.d);
console.log(d.STAT);
EDIT in response to OP edits rdSTAT
will be undefined because d
is interpreted as a String, not a Object. 响应OP编辑的
rdSTAT
EDIT将是未定义的,因为d
被解释为字符串,而不是对象。 That's why you'll have to parse it or update the webservice to remove the quotes around the value of d
. 这就是为什么您必须解析它或更新Web服务以删除
d
值附近的引号的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.