我的疑问句。很简单,但没有人问也不回答了。
My ques. is simple yet no one has asked it nor answered it.
我有一个平坦的JSON:
I have a flat JSON:
{"number1":"value1", "number2":"value2", "number3":"value3" }
我可以将其设置为JSONObject的就好了。但是,我不通过各项目知道如何循环并获得其关键字符串,字符串值。
I can set it to a JSONObject just fine. However, I don't know how to loop through each item and get its key string and value string.
任何人都可以提供一个高效的code使用的JSONObject?我真正想要的是让每个项目的键和值W / O pre-知道密钥,也没有价值。
Can anyone provide an efficient code for using JSONObject? What I really want is to get each item's key and value w/o pre-knowing the key nor value.
在此先感谢。
使用的keys()迭代器遍历所有属性,并调用get()每个
Iterator<String> iter = json.keys();
while (iter.hasNext()) {
String key = iter.next();
try {
Object value = json.get(key);
} catch (JSONException e) {
// Something went wrong!
}
}