Create HashMap from a JSON String with Robospice Retrofit

283 views Asked by At

How to create a HashMap from a JSON string with robospice retrofit?

"0": {

    "civility": "M.",
    "last_name": "Test",
    "first_name": "",
    "postal_code": "91200",
    "city": "ATHIS MONS",
    "address": "Rue royale"
  },

  "1": {
    "civility": "M.",
    "last_name": "Test",
    "first_name": "",
    "postal_code": "75013",
    "city": "PARIS 13",
    "address": "test"
  }
1

There are 1 answers

1
Krishna V On BEST ANSWER

Parse the JSONObject and create HashMap

public static void jsonToMap(String t) throws JSONException {

        HashMap<String, String> map = new HashMap<String, String>();
        JSONObject jObject = new JSONObject(t);
        Iterator<?> keys = jObject.keys();

        while( keys.hasNext() ){
            String key = (String)keys.next();
            String value = jObject.getString(key); 
            map.put(key, value);

        }

        System.out.println("json : "+jObject);
        System.out.println("map : "+map);
    }