I am new to Android/ Java programming and need help in knowing how to convert json map to a java hashmap. Please refer the code below:
HttpPost httpPost1 = new HttpPost(
"http://www.mywebsite.com/something.json" );
Log.i("MAP", "Hash call");
List<NameValuePair> nameValuePair1 = new ArrayList<NameValuePair>(1);
nameValuePair1.add(new BasicNameValuePair("id_token", token ));
try {
httpPost1.setEntity(new UrlEncodedFormEntity(nameValuePair1));
} catch (UnsupportedEncodingException e) {
// writing error to Log
e.printStackTrace();
}
try {
HttpResponse response1 = httpClient.execute(httpPost1);
BufferedReader reader = new BufferedReader(newInputStreamReader(response1.getEntity().getContent(), "UTF-8"));
StringBuilder builder = new StringBuilder();
for (line = null; (line = reader.readLine()) != null;) {
// builder.append(line).append("\n");
System.out.println(line); }
This code returns me a jason map, which has been shown below:
{"myemailid@gmail.com":[{"lat":0.0,"lng":0.0,"tim":"2014-10-01T16:55:15.002Z"},{"lat":0.0,"lng":0.0,"tim":"2014-10-01T16:18:07.290Z"},{"lat":0.0,"lng":0.0,"tim":"2014-10-01T12:04:06.364Z"},{"lat":0.0,"lng":0.0,"tim":"2014-10-01T11:58:04.455Z"},{"lat":0.0,"lng":0.0,"tim":"2014-10-01T11:46:24.560Z"}]}
What I need is to convert this json map to java hashmap. I would highly appreciate if I could be guided on this.