• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Tim Cooke
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
Saloon Keepers:
  • Piet Souris
Bartenders:

Unable to extract data from JSON API

 
Greenhorn
Posts: 6
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to pull only the Routes from this JSON API output. This code will pull all the data:



When I try to convert from JSON and grab only Routes I only get this as my output: @783e6358

 
Marshal
Posts: 4953
625
VSCode Eclipse IDE Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are missing an HTTP Accept header specifying the type of content you want, and the site is returning you XML:

If you adding Accept: application/json, you will get:
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arrays, like your BusRoute[], don't have a toString() of their own, so fall back to the Object toString.
So when you print them they will just print what you see.
The Arrays utility class has a toString method that will handle this.

However, since your BusRoute class has no toString then each entry in the array will appear as the default toString, so you probably want to override toString in your BusRoute as well.
 
reply
    Bookmark Topic Watch Topic
  • New Topic