Convert Json To Array Via Javascript
Possible Duplicate: JSON to javaScript array Can anybody point me out how i can convert a json data to an array using java script in order to draw a chart from de data. The JSON
Solution 1:
var sampleData = [], results = d.results;
for (var i = 0, len = results.length; i < len; i++) {
var result = results[i];
sampleData.push({ name: result.Name, Age: result.Age, Sex: result.Sex });
}
Solution 2:
You just have to iterate through the results array in your javascript object and build a new array that has the data in the format you want.
var results = data.d.results;
var sampleData = [], item;
for (var i = 0, len = results.length; i < len; i++) {
item = results[i];
sampleData.push({name: item.Name, Age: item.Age, Sex: item.Sex});
}
Post a Comment for "Convert Json To Array Via Javascript"