我在服务器上发送了一些请求,它回复了我:
{
"count": 100,
"entries": [
{
"id": 7563,
"application": "my-app",
"user": "admin",
"time": "2012-10-10T11:32:09.324+07:00",
"values": {
"/my-app/name": "4d79f56b-1a20-4b25-bff6-b5f1d7253790"
}
},
{
"id": 7561,
"application": "my-app",
"user": "admin",
"time": "2012-10-10T11:32:08.687+07:00",
"values": {
"/my-app/name": "4d79f56b-1a20-4b25-bff6-b5f1d7253790"
}
}
}
我试过,但似乎没有什么对我有用!
var my_JSON_object = {};
var xmlhttp = new XMLHttpRequest();
my_JSON_object = JSON.parse(xmlhttp.responseText);
xmlhttp.open("GET",url,true);
xmlhttp.sand();
一切都很好。但值会返回null 任何帮助将不胜感激!
答案 0 :(得分:3)
更正您的代码:
xmlhttp.open("GET",url,false);
xmlhttp.send();
//get response after sending request
my_JSON_object = JSON.parse(xmlhttp.responseText);
答案 1 :(得分:1)
alert(my_JSON_object.entries.id);
答案 2 :(得分:0)
最简单的方法就是使用jQuery来实现它:
$.getJSON(url, function(data) {
alert(data.count);
...
});