• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to extract JSON Response in JQuery function  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

This is my JSON Response inside my servlet shown from Firebug .


I am unable to access this data inside my jquery function .

success: function(data) {
drawChart(data);
},

function drawChart(data)
{
for(var i = 0 ; i < data.jobs.length ; i++){

alert(data.jobs.id[i]); // This is not working , please help . Thank you .
}
}[/code]
 
Nikhil Wanpal
Greenhorn
Posts: 11
Eclipse IDE Firefox Browser jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per the code you have written here, you have not parsed the json data obtained into a javascript object, and so "data.jobs.id[i]" will have no meaning as yet. Check my response to you previous post: http://www.coderanch.com/t/528797/HTML-JavaScript/parse-JSON-Object-javascript
You can try this, just to check: var myJSObj = eval(data); and then loop over the new object and alert the values.
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nikhil I will try
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now i tried this way as


My JSOn response what i am getting in firebug response as

jobs:[{id:"2009,06,16",title:"2"},{id:"2009,06,18",title:"4"},{id:"2009,06,20",title:"6"},{id:"2009,06,22",title:"8"},{id:"2009,06,24",title:"10"},{id:"2009,06,26",title:"12"}]}

I got this error in Firebug


missing ] after element list
[Break On This Error] ([object Object])


please help , i am struck .
 
Nikhil Wanpal
Greenhorn
Posts: 11
Eclipse IDE Firefox Browser jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See if this example explains it any better:



...and in your post above you probably have missed the first '{' before "jobs".
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Nikhil , your responses were fast .

Anyhow i solved this by this way :


$.each(data.jobs, function(index,job) {

PurchasesData.setValue(index, 0, new Date(job.id));
PurchasesData.setValue(index, 1, parseInt(job.title));

}
);
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Proper JSON has quotes



If the quotes are missing, JavaScript's JSON will not parse the string into an object.

Eric
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!