如何获取JSON响应的最后一个元素?
...
var array_response = $.parseJSON(response);
var index = 0;
for (index = 0; index < response.length; index++) {
var stato = array_response[index]["name"];
var id = array_response[index]["id"];
$('#owl-sensori-allarmi').append("");
} // END FOR
}
这是JSON代码:
[{
"id": "1",
"place": "Stanzina",
"state": "1"
}, {
"id": "3",
"place": "Sala",
"state": "0"
}]
谢谢!
SOLVE:
var array_response = $.parseJSON(response); var room = array_response[array_response.length -1]["id"];