数组的索引值
我有一个json文件,其内容如下:
I have a json file with contents like this:
{
"aaa":{
"status":"available",
"classkey":"dotnet"
},
"bbb":{
"ccc":{
"com":"available",
"net":"available",
"info":"available",
"org":"available"
}
}
}
现在,我想按索引获取数组的值(例如,像xxx[0]
这样的xxx[0]
而不是xxx['aaa']
).我怎么做?
Now I want to fetch the value of array by index (ex., xxx[0]
like this not like xxx['aaa']
). How do I do that?
您不能.不能保证json和大多数其他键值数据结构中的顺序.此外,您没有数组,但是有一个对象.如果不打算使用名称访问值,为什么要完全使用名称/值对?其中存在json和其他键值数据存储的功能.如果需要通过整数索引访问值,则只需使用数组来存储数据.
You can't. Order is not guaranteed in json and most other key-value data structures. Furthermore you don't have an array, you have an object. Why use name-value pairs at all if you aren't going to use the names to access the values? Therein lies the power of json and other key-value data stores. If you need to access the values by integer indexes, then just use an array to store your data.