[SOLVED]
private void jsonObjectToMap(JSONObject jsonObject) throws JSONException {
Map<String,String> map = new HashMap<String,String>();
Iterator iter = jsonObject.keys();
while(iter.hasNext()) {
String key = (String) iter.next();
JSONObject value = jsonObject.getJSONObject(key);
Iterator iter2 = value.keys();
while (iter2.hasNext()) {
String key2 = (String) iter2.next();
Object value2 = value.get(key2);
map.put(key2,value.toString());
System.out.println(key2 + " : " + value2);
}
}
i have the following JSON (see "json" below), using these methods, I always get "1"
as key
and "{"this": 1, "is": 1,"an": 1, "example": 1,"text": 1}
as value
. I would like to have each word in the brackets as separated keys
and the associated numbers a value
.
this the last code i tried:
for(int i = 0; i < jsonObject.names().length(); i++){
System.out.println("key = " + jsonObject.names().getString(i) +
" value = " + jsonObject.get(jsonObject.names().getString(i)));
}
json:
"1": {
"this": 1,
"is": 1,
"an": 1,
"example": 1,
"text": 1
}
Whole JSON, but i isolated the json-object "1"
"output": {
"status": 1,
"result": {
"1": {
"this": 1,
"is": 1,
"an": 1,
"example": 1,
"text": 1
}
}
}