0

I am sending some request on a server and it's reply me this:

{
    "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"
            }
        }
}

I tried, but nothing seems to working for me!

 var my_JSON_object = {};
 var xmlhttp = new XMLHttpRequest();

 my_JSON_object = JSON.parse(xmlhttp.responseText);

 xmlhttp.open("GET",url,true);
 xmlhttp.sand();

Everything is fine. but values return null.
Any help would be appreciated!

[my code]

6LYTH3
  • 1,426
  • 1
  • 10
  • 9

3 Answers3

3

correct your code:

 xmlhttp.open("GET",url,false);
 xmlhttp.send();

 //get response after sending request
 my_JSON_object = JSON.parse(xmlhttp.responseText);
flyingzl
  • 1,811
  • 3
  • 15
  • 18
1
 alert(my_JSON_object.entries.id);
Man Programmer
  • 5,300
  • 2
  • 21
  • 21
0

Easiest way is just to use jQuery to do it:

$.getJSON(url, function(data) {
    alert(data.count);
    ...
});
PhonicUK
  • 13,486
  • 4
  • 43
  • 62