[英]Array of arrays json Javascript, ajax response
Im trying to access to parameter value from response. 我试图从响应访问参数值。
$.ajax({
type: "POST",
url: "",
dataType: 'text',
async: false,
headers: {
"Authorization": "Basic " + btoa(username + ":" + password)
},
data: '{ "action" : "create", "resource" : {"name" : "teddssssssssddsssdsddddsdddwdsdssdsddi", "description": "Test Tenant Description","parent": {"href": "localhost"}}}',
success: function(as) {
alert(as[0][0]["id"]);
}
});
in the success area i got the response, in json. 在成功区域中,我得到了json中的响应。 I want to access to the id value, but i cant.
我想访问id值,但是我不能。 always says undefined, i tried different options.
总是说未定义,我尝试了不同的选择。 this is the response format.
这是响应格式。
{
"results": [
{
"href": "localhost/1111111",
"id": "100000000111",
"name": "test",
"ancestry": "1000011111",
"divisible": true,
"description": "Test Tenant Description",
"use_config_for_attributes": false,
"default_miq_group_id": "10021200000173"
}
]
}
I dont know if i can access direct to the parameter or better get the response as text and split. 我不知道我是否可以直接访问参数或更好地获得响应作为文本和拆分。
The response has a different structure. 响应具有不同的结构。 Your response is an object with one property and value is an array of objects.
您的响应是一个具有一个属性的对象,而值是一个对象数组。
something like {'results': [...{}]} 类似于{'results :: [... {}]}
Key 0 does not exist. 密钥0不存在。
const data = {"results":[{"href":"localhost/1111111","id":"100000000111","name":"test","ancestry":"1000011111","divisible":true,"description":"Test Tenant Description","use_config_for_attributes":false,"default_miq_group_id":"10021200000173"}]}; console.log(data.results[0].id);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.