Monday, November 24, 2014

Android java enumerate JSONObject child items code

1.what

i need enumerate the JSONObject child item key and value by code

2.how

            JSONObject obj = null; // please set this not null value in first


Iterator<String> k = obj.keys();
String key;
Object value;
while(k.hasNext()){
key = k.next();
value = obj.opt(key);
if(value == null || obj.isNull(key))
continue;

if(value instanceof JSONArray){
JSONArray jary = (JSONArray)value;

}else if(value instanceof JSONObject){
JSONObject jobj = (JSONObject)value;

}else if(value instanceof String){
String s = (String)value;

}else if(value instanceof Long){
Long l = (Long)value;

}else if(value instanceof Integer){
Integer l = (Integer)value;

}else if(value instanceof Boolean){
Boolean b = (Boolean)value;

}else if(value instanceof Double){
Double d = (Double)value;
}
}



3.Last:



Thanks!

No comments: