[英]Problems Reading json data return to jQuery
I have some json return data, I am unable to access any of the data within the JSON, I have used this method before and it works, but I can't seem to figure out what is going wrong here. 我有一些JSON返回数据,我无法访问JSON中的任何数据,我以前使用过此方法并且它可以工作,但是我似乎无法弄清楚这里出了什么问题。
the data["json"] will print out the json data but data["default"] or data.default will not print out the individual information within the json data. data [“ json”]将打印出json数据,但data [“ default”]或data.default将不会打印出json数据中的各个信息。
JSON: {"default":"y","mqdefault":"y","hqdefault":"y","sddefault":"y","maxresdefault":"y"} JSON:{“默认”:“ y”,“ mqdefault”:“ y”,“ hqdefault”:“ y”,“ sddefault”:“ y”,“ maxresdefault”:“ y”}
the jquery is: 的jQuery是:
$.ajax({
type: "POST",
dataType: "json",
url: "response.php",
data: data,
success: function(data) {
$(".the-return").html(
"default: " + data["default"] + "<br />mqdefault: " + data["mqdefault"] + "<br />hqdefault: " + data["hqdefault"] + "<br />JSON: " + data["json"]
);
//alert("Form submitted successfully.\nReturned json: " + data["json"]);
}
});
Well i had run into a similar type of situation where i was getting a json data in the response from my server that i was able to print in log, but i was not able to access its variables. 好吧,我遇到了类似的情况,我从服务器的响应中获取了json数据,可以在日志中打印,但是无法访问其变量。
Later i found out that this was because the data that was being received in the callback success function was not actually a json value. 后来我发现这是因为在回调成功函数中接收到的数据实际上不是json值。 You might need to check if it is actually a json or else you can parse it to a json.
您可能需要检查它是否实际上是json,否则可以将其解析为json。
Possibly your data is not a proper json format due to which you are not able to access data["default"] 由于您无法访问数据,因此您的数据可能不是正确的json格式[“默认”]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.