JSON of this type comes

{ "meta": { "code": 200 }, "data": [{ "attribution": null, "tags": ["02q"], "location": null, "comments": { "count": 71, "data": [{ "created_time": "1349883158", "text": "Great shot\u2661", "from": { "username": "sakura_yumi", "profile_picture": "http:\/\/ images.instagram.com \/profiles\/profile_54578142_75sq_1348218646.jpg", "id": "54578142", "full_name": "yumi" }, "id": "299164076294750525" }, 

I think that for sure there is a ready-made example of how to partake such an answer. Please help the code.

  • @AlexRudenkiy, something doubtful to me here these tags seem. Especially about api. - Qwertiy

2 answers 2

If the given JSON text is in your variable eg. JSONtext , then:

 var Insta = eval( '(' + JSONtext + ')' ); var code = Insta.meta.code; /* 200 */ alert( Insta.data.comments.count + ' комментов'); 

JSON has a native JavaScript syntax. You can write directly:

 var iObject = { "meta": { "code": 200 }}; alert( iObject.meta.code ); 
  • No, this JSON text is not in a variable from me, I actually just pick it up from the API, that is, this page - Drac0Sha
  • What are you taking? - Sergiks
  • Yes, basically nothing. I have not thought about it yet. I thought for now, by hand, just copy everything and check the parser. or is this not the right approach? - Drac0Sha
  • It is not clear what you are doing, why, and what plans) - Sergiks
  • just interesting to work with the API of Instagram, I want to parse from there photos with a certain hashtag - Drac0Sha

on jquery you can parse such a response into an object by calling the getJSON () method

  • thanks, I'll try to figure it out - Drac0Sha