通过索引获取JSON对象的特定值?

时间:2014-02-12 09:44:14

标签: json

我一直在尝试使用JSON对象的特定字段。

当我使用时:

console.log(item);

结果:

[{"userid":"111","username":"","usertype":"0","emailaddress":"","phonenumber":"","faxnumber":"","cellnumber":"","gender":"5","race":"1","country":"1"}] 

当我使用时:

console.log(item.userid);

结果:

undefined 

2 个答案:

答案 0 :(得分:4)

您必须迭代数组,然后获取特定项

答案 1 :(得分:0)

尝试使用

 for(var i=o;i<item.length;i++)
 {
  console.log(item[i].userid);
 }