Json Object - Getting the Key and the Value

后端 未结 3 1915
再見小時候
再見小時候 2021-01-07 15:44

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

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-07 16:07

    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 keys = jsonObject.keys();
    if( keys.hasNext() ){
       String key = (String)keys.next(); // First key in your json object
    }
    

提交回复
热议问题