JSON对象 - 获取键和值 [英] Json Object - Getting the Key and the Value
本文介绍了JSON对象 - 获取键和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个新手,JSON。所以,如果这是一个非常基本的疑问,别骂我。我有一个JSON对象引用,我想拿到钥匙(对象只有一个键值对)。如何获得它在Java中?
I am a newbie to JSON . So If this is a very basic doubt don't scold me . I have a JSON Object Reference and I want to get the Key(Object has only one Key Value Pair) . How do I get it in Java ?
推荐答案
您可以使用 jsonObject.keys()
获取所有的键。然后你可以遍历键率先拿到钥匙了出来,如:
You can use jsonObject.keys()
for getting all keys. Then you may iterate over keys to get the first key out of them like :
Iterator<String> keys = jsonObject.keys();
if( keys.hasNext() ){
String key = (String)keys.next(); // First key in your json object
}
这篇关于JSON对象 - 获取键和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文