ajax - how to use json Value in javascript or convert simple string in json object? -
var info = [ {label: "a organinzation",data: 1}, {label: "b pvt ltd.",data: 2}, {label: "d organization",data: 10}, {label: "completed organization",data: 15}, {label: "running organization",data: 34} ];
i have 1 piechart of jqplot in jsp page , takes info above format..now problem worked fine static data. when want include dynamic data. shows blank chart because of info variable cant parse string providing... generating same string specified in above code snippet next
var total = rawdata.split(";"); var txt = null; (var = 1; < total.length - 1; i++) { if (i == 1) { txt = "{ label: \"" + total[i] + "\", data: " + total[i + 1] + "}"; } else { txt = txt + ", { label: \"" + total[i] + "\", data: " + total[i + 1] + "}"; } i++; } alert(txt); elem = $('#fl_3'); var info = [json.parse(txt)];
when alert txt varibale giving me next pattern same code snippet gave @ first...
{ label: "abc ltd.", data: 42}, { label: "a org", data: 2}, { label: "b org", data: 6}, { label: "c org", data: 1}, { label: "dbc comp ltd", data: 1}, { label: "avc comp pvt. ltd", data: 1}
then why cant parse json? in browser, got error:
class="lang-noe prettyprint-override">error: syntaxerror: json.parse: expected property name or '}'
if write data=[txt];
, nil appears. if write data = [json.parse(txt)];
error..
can please help me? how can create run?
why building string @ , parse object if have info in array? maybe need reformat total
somehow. not sure construction of total
array. play this:
var info = []; (var = 0; < total.length - 1; = + 2) { data.push({label: total[i], data: total[i + 1]}); }
note: i'm assuming here rawdata
looks string:
"a organinzation;1;b pvt ltd.;2;completed organization;3";
javascript ajax json jqplot
No comments:
Post a Comment