Parse Json array from google maps api in Java -


i json array https://maps.googleapis.com/maps/api/geocode/json?address=10115,germany google maps api. want parse in java , part "location" "lat" , "lng" don´t know how it.

here code -

import java.io.bufferedreader; import java.io.inputstream; import java.io.inputstreamreader;  import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.client.httpclient; import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.defaulthttpclient; import org.json.simple.jsonarray; import org.json.simple.jsonobject; import org.json.simple.parser.jsonparser; import org.json.simple.parser.parseexception;  public class jsonreader {      public static void main(string[] args) throws parseexception  {               inputstream inputstream = null;             string json = "";              try {                            httpclient client = new defaulthttpclient();                   httppost post = new httppost("https://maps.googleapis.com/maps/api/geocode/json?address=10115,germany");                 httpresponse response = client.execute(post);                 httpentity entity = response.getentity();                 inputstream = entity.getcontent();             } catch(exception e) {             }              try {                            bufferedreader reader = new bufferedreader(new inputstreamreader(inputstream,"utf-8"),8);                 stringbuilder sbuild = new stringbuilder();                 string line = null;                 while ((line = reader.readline()) != null) {                     sbuild.append(line);                 }                 inputstream.close();                 json = sbuild.tostring();                            } catch(exception e) {             }               //now parse             jsonparser parser = new jsonparser();             object obj = parser.parse(json);             jsonobject jb = (jsonobject) obj;              //now read             jsonarray jsonobject1 = (jsonarray) jb.get("results");             jsonobject jsonobject2 = (jsonobject)jsonobject1.get(0);             jsonobject jsonobject3 = (jsonobject)jsonobject2.get("geometry");             jsonobject location = (jsonobject) jsonobject3.get("location");              system.out.println( "lat = "+location.get("lat"));             system.out.println( "lng = "+location.get("lng"));           }     } 

output-

lat = 52.532614 lng = 13.3777035 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -