jonney jonney - 2 years ago 95
Java Question

Putting HashMap<String, object> in jsonobject

i building a json object that consists of nameValue pairs defined in a Hashmap

the issue i am having is when i invoke:


It adds the nameValue pairs like this:

instead of

Any thoughts?


Answer Source

Iterate through the HashMap and put to the jsonObject:

Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
    Map.Entry pairs = (Map.Entry);
    jsonObject.put(pairs.getKey(), pairs.getValue() );
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download