• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Unable to parse the JSON string and get the desired result

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unable to parse the JSON string and get the desired result, Below is the code i have used


URLConnection connection = new URL("https://www.ixigo.com/rest/content/namedentity/v2/city/id?sort=po&order=dsc&cityId=50bc587de4b03caba7c068b8&entityId=1&type=Church&keys=attr_map%2Cc%2Cr%2Cns%2Cst%2Ci%2Ca%2Cef%2Cpr%2Cki%2Cpo%2Ct%2Clc%2Cf%2C_id%2C_oid%2Cad%2Cu%2Cseou%2Cla%2Cln%2Ccst%2Cd%2Cwhy%2Cur%2Curc%2Ccn%2Cco%2Cdesrm%2Cwho%2CtipCount&limit=15&skip=0&filterKeys=&filterValues=").openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.95 Safari/537.11");
connection.connect();

BufferedReader br  = new BufferedReader(new InputStreamReader(connection.getInputStream(), Charset.forName("UTF-8")));

StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
    sb.append(line);
}
System.out.println(sb.toString());

JSONParser parse = new JSONParser();
JSONObject jobj = (JSONObject)parse.parse(sb.toString());
System.out.println(jobj);
JSONArray jsonarr_1 = (JSONArray) jobj.get("data");
//Get data for Results array
for(int i=0;i<jsonarr_1.size();i++)
{
//Store the JSON objects in an array
//Get the index of the JSON object and print the values as per the index
JSONObject jsonobj_1 = (JSONObject)jsonarr_1.get(i);
System.out.println("Elements under results array");
System.out.println("\nPlace id: " +jsonobj_1.get("_id"));
System.out.println("Types: " +jsonobj_1.get("types"));
 
Saloon Keeper
Posts: 5776
146
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does the code do, and how does that deviate from what you expected it to do? At what point in the code does that happen?

Remember that we don't have the code running, so we don't know what its output is.
 
sourabh shukla
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Tim Moores wrote:What does the code do, and how does that deviate from what you expected it to do? At what point in the code does that happen?

Remember that we don't have the code running, so we don't know what its output is.



Please check the below url output in JSON viewer online and you will understand what is the output and why i am facing the issue.

https://www.ixigo.com/rest/content/namedentity/v2/city/id?sort=po&order=dsc&cityId=50bc587de4b03caba7c068b8&entityId=1&type=Church&keys=attr_map%2Cc%2Cr%2Cns%2Cst%2Ci%2Ca%2Cef%2Cpr%2Cki%2Cpo%2Ct%2Clc%2Cf%2C_id%2C_oid%2Cad%2Cu%2Cseou%2Cla%2Cln%2Ccst%2Cd%2Cwhy%2Cur%2Curc%2Ccn%2Cco%2Cdesrm%2Cwho%2CtipCount&limit=15&skip=0&filterKeys=&filterValues=
 
Master Rancher
Posts: 4223
47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most people won't go to some renadom website on the off chance of seeing what you are having issues with.

That site (according to your code) should be returning some Json.

So post the relevant bit of Json here (you're logging it in your code, so that part shouldn't be a problem), since that appears to show the problem you are having.
 
A wop bop a lu bop a womp bam boom! Tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!