请考虑以下JSON对象:
Object {
[i24] => Object {
[name] => Mike
[gender] => male
}
[i26] => Object {
[name] => John
[gender] => male
}
[i32] => Object {
[name] => Mary
[gender] => female
}
}
如何将指针移动到主对象中的上一个/下一个项目?或者(也许更好),我怎样才能获得第X个对象?例如。格式为jsonObject[X]
答案 0 :(得分:1)
好的,我会自己回答这个问题:)
解决方案是使用Object.keys():
var keysArray = Object.keys(JSONobject);
//to get the 2nd item of object
var secondObj = JSONobject[keysArray[1]]; // this will return i26 in given example.