jquery - Why do I have to JSON.stringify before I .parseJSON a result set from Google+ API? -
i started playing around google+ api , have scoured docs. seems pretty straight forward. according google, call on api returns json. why have stringify json before parsing json before call key values in jquery? here sample of code working with:
$.ajax({ url: "https://www.googleapis.com/plus/v1/people/{user number}/activities/public?key={my api key}", data: { "maxresults": 20, "verb": "post" }, datatype: "json", type: "get", success: function (data) { var num_actual_posts = 0; data = $.parsejson(json.stringify(data)); var listelements = $('ul#googlefeedul li'); (var = 0; < data.items.length; i++) { if (data.items[i].verb == "post") { $(listelements[num_actual_posts]).append(data.items[i].object.content); num_actual_posts++; if (num_actual_posts > 5) { break; } } } }, error: function (e) { alert(e); } });
note: have call 20 posts, because "shares" made user returned when "post" verb requested reason. actual posts within returned json in order display real posts. docs don't seem tell how extract data explaining json object hierarchy, had track down through console. 'data.items[i].object.content' content of google+ post.
your ajax call specifies datatype: "json"
, jquery parse returned json javascript object.
you should able drop
data = $.parsejson(json.stringify(data));
altogether data
desired object.
Comments
Post a Comment