如何使用javascript访问json对象
How to access json object using javascript?
我不是json解析专家,所以如果我问一个简单的问题,请原谅我。我有一个json响应像这样:
{
"resp": [{
"Key": "123423544235343211421412",
"id": "12"
}]
}
我想访问key和id的值(123423544235343211421412,12)我试着遵循,但我不能得到的值!
如果你们告诉我如何得到这些值,我会很感激。由于
var postData = {
Name: "Galaxy",
action: "token"
};
$.ajax("https://someapiurl/getit.aspx",{
type : 'POST',
data: JSON.stringify(postData),
contentType: "application/json",
success: function(data) {
var json = JSON.parse(data);
alert(json.resp[0].Key);
alert(json.resp[1].id);
},
contentType: "application/json",
dataType: 'json'
});
你就快成功了。当您指定dataType: 'json'
$.ajax('https://someapiurl/getit.aspx', {
method: 'POST',
contentType: 'application/json; charset=UTF-8',
dataType: 'json',
data: JSON.stringify(postData)
}).done(function(obj) {
alert(obj.resp[0].Key);
alert(obj.resp[0].id);
})
相关文章:
- jQuery匹配JSON对象的部分文本
- 如何在Javascript中将JSon对象转换为数组
- 我可以在json对象中添加一个函数吗
- 使用JS将数组转换为json对象
- 如何为json对象中的段发送array[]
- 将JSON对象传递给angular指令
- 更改JSON对象的结构
- 访问JSON对象内部的数组元素
- 在ejs-partial中对JSON对象进行迭代
- 遍历 JSON 对象并检查 URL 是否以某个值结尾
- 访问嵌套JSON对象的键,其中键是动态的
- json对象中缺少对象循环
- 发送json对象或使用express路由呈现视图
- 在play2框架中向json对象添加下拉列表项
- 元素名称上带有短划线 (-) 字符的 Json 对象
- autocomplete不接受源的json对象
- 如何在javascript中创建动态json对象
- 在使用客户端脚本时拾取JSON对象
- 如何通过json对象数组为嵌套对象赋值
- 构造JSON对象