我是一个新手,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
}