获取jsonarray键名 [英] Get jsonarray key name
本文介绍了获取jsonarray键名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要得到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();
}
}
这篇关于获取jsonarray键名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文