¿我如何(使用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。
答案 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);