Java 从JSONObject检索所有字符串和值

Java 从JSONObject检索所有字符串和值,java,android,Java,Android,我目前有一个JSONObject,它包含不同类型的带有布尔值的字符串。如何获取对象中的所有字符串和值 JSONObject: { "1ed1":false, "1ed3":true, "1ep2":true } 如果JsonObject中只有布尔值,请尝试以下解决方案: Iterator<?> keys = json.keys(); // json is your `JsonObject` while( keys.hasNext() ) { String key = (St

我目前有一个JSONObject,它包含不同类型的带有布尔值的字符串。如何获取对象中的所有字符串和值

JSONObject:

{ "1ed1":false, "1ed3":true, "1ep2":true }

如果
JsonObject
中只有布尔值,请尝试以下解决方案:

Iterator<?> keys = json.keys(); // json is your `JsonObject`
while( keys.hasNext() ) {
    String key = (String)keys.next();
    Log.e("key",""+key); // This will give you all the keys of your jsonObject, in your case it will be 1ed1,1ed3 etc...
    Log.e("value",""+json.getBoolean(key)); // This will give all the values associated with the key
}
Iterator keys=json.keys();//json是您的`JsonObject`
while(keys.hasNext()){
字符串键=(字符串)键。下一步();
Log.e(“key”,“key+”);//这将为您提供jsonObject的所有键,在您的情况下,它将是1ed1,1ed3等等。。。
Log.e(“value”,“”+json.getBoolean(key));//这将给出与该键关联的所有值
}

好的,问题是什么?@Simze如何获取对象中的所有字符串和值。如果不是很清楚的话,很抱歉。这相当有帮助!但是我如何对对象中的所有字符串而不是一个字符串执行此操作?
Iterator<?> keys = json.keys(); // json is your `JsonObject`
while( keys.hasNext() ) {
    String key = (String)keys.next();
    Log.e("key",""+key); // This will give you all the keys of your jsonObject, in your case it will be 1ed1,1ed3 etc...
    Log.e("value",""+json.getBoolean(key)); // This will give all the values associated with the key
}