我有一个外部文件people.json。如何将其转换为具有 json 语法的 javascript 数组?
这是people.json的内容:
{
"1":{
"Name":"Jhon",
"Surname":"Kenneth",
"mobile":329129293,
"email":"jhon@gmail.com"
},
"2":{
"Name":"Thor",
"Surname":"zvalk",
"mobile":349229293,
"email":"thor@gmail.com"
},
"3":{
"Name":"Mila",
"Surname":"Kvuls",
"mobile":329121293,
"email":"mila@gmail.com"
}
}
我想要一个这种格式的数组
var person = [
{ "name":"jhon" , "surname":"kenneth", "mobile":329129293, "email":"jhon@gmail.com"},
{ "Name":"Thor", "Surname":"zvalk", "mobile":349229293, "email":"thor@gmail.com" },
{ "Name":"Mila", "Surname":"Kvuls", "mobile":329121293, "email":"mila@gmail.com"}
];
我尝试使用下一个代码,但它不起作用:
var person;
$.getJSON('people.json', function (json) {
person[]= json
});
顺便说一句,文件contacts.json 在我的服务器中。