Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
13
rated 0 times [  14] [ 1]  / answers: 1 / hits: 31866  / 12 Years ago, sat, january 26, 2013, 12:00:00

I have an external file contacts.json. How I can convert it to a javascript array?

this is the contacts.json content:



{
ppl1:{
Name:Jhon,
Surname:Kenneth,
mobile:329129293,
email:[email protected]
},
ppl2:{
Name:Thor,
Surname:zvalk,
mobile:349229293,
email:[email protected]
},
ppl3:{
Name:Mila,
Surname:Kvuls,
mobile:329121293,
email:[email protected]
}
}

More From » jquery

 Answers
8

Solved:



$.getJSON('contacts.json', function (json) {
var array = [];
for (var key in json) {
if (json.hasOwnProperty(key)) {
var item = json[key];
array.push({
name: item.Name,
surname: item.Surname,
mobile: item.mobile,
email: item.email
});
}
}
});

[#80603] Friday, January 25, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ravenl

Total Points: 338
Total Questions: 107
Total Answers: 112

Location: Belize
Member since Mon, Jun 20, 2022
2 Years ago
ravenl questions
Thu, Feb 18, 21, 00:00, 3 Years ago
Tue, Jan 12, 21, 00:00, 3 Years ago
Tue, Mar 17, 20, 00:00, 4 Years ago
;