来自jsonp的数据

时间:2013-02-06 22:46:27

标签: jquery json jsonp

¿我如何(使用Jquery)从这个json结果中获取特定值?例如,电子邮件

 [
 {
   address: "",
   province: "",
   firstName: "Anna",
   email: "anna@example.org",
   postalCode: "",
   key: "135",
   type: "technical",
   description: "",
   isPrimaryContact: true,
   phone: "",
   country: "",
   city: "",
   salutation: "",
   position: " Projects Leader, Academic Systems",
   lastName: ""
 }
]

我使用$ .ajax(),来自不同服务器的json。

1 个答案:

答案 0 :(得分:0)

如果你有一个JSON对象,你只需使用:

var email = data.email;

这是一个完整的,缩短的例子:

 var data = {
   address: "",
   province: "",
   firstName: "Anna",
   email: "anna@example.org"
 };

alert(data.email);

如果您的数据确实是一个数组,则需要使用:

alert(data[0].email);

类似的缩写示例:

 var data = [{
   address: "",
   province: "",
   firstName: "Anna",
   email: "anna@example.org"
 }];

alert(data[0].email);