JQuery doesn't parse JSON correctly

I have a problem. I built a script to request an internal link that sends a response. This looks like a script:

jQuery.get(callUrl, function(data){
              console.log(typeof data);
              jQuery.each(data.items, function(i,item){            

                                      console.log(i);

                                });
        },'json');

and the response that the server sends is as follows:

{"items":[            
  {
   "src": "gallery_item_data_Jc4EaLP6vlwd_large.jpg",
   "id": "83",
   "gallery_id": "30",
   "username": "admin"
  }]
}

My problem is that when I parse "data", its type is always a string. I need this to be an object, so I can query it and parse it with a script. To understand the essence of the problem, I tried to compare my script with an example on the jQuery documentation page:

http://docs.jquery.com/Ajax/jQuery.getJSON

, getJSON. URL- , , , get, "json".

, : Flickr feed, jQuery Content-type, , , , , Flickr:

Content-Type    application/x-javascript; charset=utf-8

. . - , ?

+5
2

JSON , :

({"items":[            
  {
   "src": "gallery_item_data_Jc4EaLP6vlwd_large.jpg",
   "id": "83",
   "gallery_id": "30",
   "username": "admin"
  }]
})

getJSON, . , eval() .

+7

, JavaScript eval()? eval () , .

+1

All Articles