我需要得到JsonArray的键名,因此JSON看起来是这样,请不,JSON是开始阵列支架,并在它里面有对象,这是做我猜是因为后端将有能力添加对象。
I need to get a key name of JsonArray, so JSON looks like this, please not, that JSON is starting with array brackets, and inside it it has objects, that was made i guess because back end will have the ability to add objects.
[
{
"tehnology": [ ]
},
{
"science": []
}
]
所以我需要从它技术和科学获得的名称,因为JSON可以动态改变,我怎么能实现呢?
So i need to get the names from it "technology" and "science", because json can dynamically change, how can I implement it?
在 JSONArray
包含的JSONObject
秒。检索每个的JSONObject
和使用键()
来访问每个定义的关键的JSONObject
The JSONArray
contains JSONObject
s. Retrieve every JSONObject
and use keys()
to access the key defined in every JSONObject
JSONArray jArray = new JSONArray(response);
for (int i = 0; i < jArray.length(); i++) {
JSONObject object = jArray.optJSONObject(i);
Iterator<String> iterator = object.keys();
while(iterator.hasNext()) {
String currentKey = iterator.next();
}
}