简体   繁体   中英

Jquery get json value

I don't know how to get every first name from json text below:

[
{
"Contact":{
    "id":"4",
    "first_name":"Richat",
    "last_name":"Chhay",
    "phone":"930345435",
    }
},
{
"Contact":{
    "id":"31",
    "first_name":"Dara",
    "last_name":"Hong",
    "phone":"930345435",
    }
}
]

what I want is how to get first_name?

Try $.each method to retrieve the value

$.each(data,function(i,val){
   alert(val.Contact.first_name);
});

Demo

You can do this

arr.forEach(function(elm){
  console.log(elm.Contact.first_name);
});

FIDDLE

将其获取为jsonArray并对其执行一个循环,为数组中的每个值获取名称并在所需的位置输出。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM