Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
46
rated 0 times [  48] [ 2]  / answers: 1 / hits: 28197  / 12 Years ago, wed, may 9, 2012, 12:00:00

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 is structured as follows:



{
d:{
results:[
{
_metadata:{
uri: http://www.something.com/hi,
type : something.preview.hi
}, Name, Sara, Age: 20, Sex : female
},
_metadata:{
uri: http://www.something.com/hi,
type : something.preview.hi
}, Name, James, Age: 20, Sex : male
}
]
}
}


I would like to convert this jason to the following format:



var sampleData = [
{ name: 'Sara', Age: 20, Sex: 'female'},
{ name: 'James', Age: 20, Sex: 'male'}
];


Does anyone have any advice on how to achieve this?


More From » json

 Answers
295
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 });
}

[#85694] Monday, May 7, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristinadomoniquel

Total Points: 320
Total Questions: 94
Total Answers: 94

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
cristinadomoniquel questions
Wed, Apr 7, 21, 00:00, 3 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Mon, Nov 23, 20, 00:00, 4 Years ago
Mon, Aug 17, 20, 00:00, 4 Years ago
;