Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

question about getString method in JSON

 
Ranch Hand
Posts: 46
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Have you all have a great day. I am new to JSON and I try to use it in my first project.
I have a question regarding the getString method in JSON which I try to get your help.

I am using net.sf.json library and my json object looks like the following :




I have a question that I would like to ask relating to an element called "geocode" which exists on my second record but it does not exist on my first record; so it gives me an error when I search for it in the following code :




and the error message was :



My goal is to be able to get "geocode" since it appears in some of my record but not all ; but i don't know yet on how to approach it.

I would like to seek your helps and expertise if you know how to handle it.

Thanks so much in advance for all of your help.

Bill
 
Ranch Hand
Posts: 100
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
A quick look at the javadocs for the library seems to say that there is an alternative method optString() which you can use. You can look at http://json-lib.sourceforge.net/apidocs/net/sf/json/JSONObject.html#optString(java.lang.String)

Hope that helps.
 
reply
    Bookmark Topic Watch Topic
  • New Topic