[英]JSON reply parse on JS
I need to parse reply from server, have a code: 我需要解析来自服务器的回复,有一个代码:
$.getJSON('http://connect.mail.ru/share_count?callback=1&url_list=http://www.google.com&func=test', function(data) {
$('#ml_counter').text(data);
});
as a reply on http://connect.mail.ru/share_count?callback=1&url_list=http://www.google.com&func=test request server gives: 作为对http://connect.mail.ru/share_count?callback=1&url_list=http://www.google.com&func=test请求服务器的回复:
test(
{
"http://www.google.com":{"shares":574,"clicks":65}
});
How can I get "574" from this? 我如何从中得到“574”?
callback: function(result) {
var yourVal = result['http://www.google.com'].shares;
}
In your situation: 在你的情况下:
.text(data['http://www.google.com'].shares);
Note that returning the url as a parameter isn't really comforting. 请注意,将url作为参数返回并不是很舒服。 You're way better of returning just the child object or a list of domain-objects (where one of the properties is something like
url
and another is the { shares .... }
object. 你最好只返回子对象或域对象列表(其中一个属性类似于
url
而另一个属性是{ shares .... }
对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.