i have following nested json object coming call:
var jsondata = jquery.ajax({ url: "http://testsite/_vti_bin/listdata.svc/projecthours", datatype: "json", async: false }).responsetext;
{ "d": { "results": [ { "__metadata": { "uri": "http://testsite/_vti_bin/listdata.svc/projecthours(1)", "etag": "w/\"1\"", "type": "microsoft.sharepoint.dataservice.projecthoursitem" }, "contenttypeid": "0x0100c5d130a92a732d4c9e8489b50657505b", "title": "ryan cruz", "hours": 35, "id": 1, "contenttype": "item", "modified": "/date(1373535682000)/", "created": "/date(1373535682000)/", "createdby": { "__deferred": { "uri": "http://testsite/_vti_bin/listdata.svc/projecthours(1)/createdby" } }, "createdbyid": 19, "modifiedby": { "__deferred": { "uri": "http://testsite/_vti_bin/listdata.svc/projecthours(1)/modifiedby" } }, "modifiedbyid": 19, "owshiddenversion": 1, "version": "1.0", "attachments": { "__deferred": { "uri": "http://testsite/_vti_bin/listdata.svc/projecthours(1)/attachments" } }, "path": "/sites/itg/resourcecenters/spwidgets/lists/projecthours" }, { "__metadata": { "uri": "http://testsite/_vti_bin/listdata.svc/projecthours(2)", "etag": "w/\"1\"", "type": "microsoft.sharepoint.dataservice.projecthoursitem" }, "contenttypeid": "0x0100c5d130a92a732d4c9e8489b50657505b", "title": "phillip phillips", "hours": 25, "id": 2, "contenttype": "item", "modified": "/date(1373535694000)/", "created": "/date(1373535694000)/", "createdby": { "__deferred": { "uri": "http://testsite/_vti_bin/listdata.svc/projecthours(2)/createdby" } }, "createdbyid": 19, "modifiedby": { "__deferred": { "uri": "http://testsite/_vti_bin/listdata.svc/projecthours(2)/modifiedby" } }, "modifiedbyid": 19, "owshiddenversion": 1, "version": "1.0", "attachments": { "__deferred": { "uri": "http://testsite/_vti_bin/listdata.svc/projecthours(2)/attachments" } }, "path": "/sites/itg/resourcecenters/spwidgets/lists/projecthours" } ] } }
i want loop through each object's title , hours attribute , save them in array can pass google chart below:
var data = google.visualization.arraytodatatable(array);
i tried following code, can't find json object:
function drawtable() { var jsondata = jquery.ajax({ url: "http://testsite/_vti_bin/listdata.svc/projecthours", datatype: "json", async: false }).responsetext; alert(jsondata); var obj = jquery.parsejson(jsondata); //alert(jsondata.length); var sampledata = [], results = d.results; (var = 0, len = results.length; < len; i++) { var result = results[i]; sampledata.push({ title: result.title, hours: result.hours}); } var data = google.visualization.arraytodatatable(obj); var chart = new google.visualization.piechart(document.getelementbyid('spchart')); chart.draw(data, {showrownumber: true}); }
please give me ideas don't stuck here rest of day. thank you!
jquery.getjson({"http://testsite/_vti_bin/listdata.svc/projecthours",{},function(d) { var sampledata = [], results = d.results; (var = 0, len = results.length; < len; i++) { var result = results[i]; sampledata.push({ title: results[i].title, hours: results[i].hours}); }; });
Comments
Post a Comment