java - How to parse a JSON REST response - NoClassDefFoundError: org/json/JSONArray -
i have following uri returns me json response.
tried parse response of request , access steps
array stops in first step.
here code:
public void getroute() throws exception { string urltoread="https://maps.googleapis.com/maps/api/directions/json?origin=41.43206,-81.38992&destination=montreal&key=xxx"; defaulthttpclient httpclient = new defaulthttpclient(); httpget getrequest = new httpget(urltoread); getrequest.addheader("accept", "application/json"); httpresponse response = httpclient.execute(getrequest); string json = ioutils.tostring(response.getentity().getcontent()); jsonarray array = new jsonarray(json); (int = 0; < array.length(); i++) { jsonobject object = array.getjsonobject(i); system.out.println(object.getjsonarray("routes")); } }
but complains with:
exception in thread "main" java.lang.noclassdeffounderror: org/json/jsonarray
the maven is:
<groupid>com.googlecode.json-simple</groupid> <artifactid>json-simple</artifactid> <version>1.1.1</version> </dependency> <dependency> <groupid>org.apache.httpcomponents</groupid> <artifactid>httpclient</artifactid> <version>4.1.1</version> </dependency>
org/json/jsonarray
you compiled wrong library and/or imported wrong class.
replace
<groupid>com.googlecode.json-simple</groupid> <artifactid>json-simple</artifactid> <version>1.1.1</version>
with
<groupid>org.json</groupid> <artifactid>json</artifactid> <version>20160810</version>
Comments
Post a Comment