wood burning stoves 2.0*
The moose likes Other Open Source Projects and the fly likes Accessing JSON property names Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Accessing JSON property names" Watch "Accessing JSON property names" New topic

Accessing JSON property names

Chris Creed
Ranch Hand

Joined: Feb 27, 2009
Posts: 67

I'm working on a way to parse JSON files and collect their contents for use elsewhere. I currently have a working example that is as follows:

I'm using the json.simple library.

Here's a sample string from the parsed file.

What my question is about is how to take this code, and have the put method be able to assign to the corresponding Map dynamically. This is what I currently have:

The ??? part is where I'm stumped. Getting the values of the current JSON line is easy enough. But how to get the property eludes me. Is there a method that I can call on this object that I'm not familiar with? A different and better way to itenerate through this? Or am I doing this completely assbackwards right from the get go?
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10167

Check out JSONObject#keys() and JSONObject#names()

[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
I agree. Here's the link: http://aspose.com/file-tools
subject: Accessing JSON property names
Similar Threads
NPE when wrapping a Reader in a BufferedReader twice
Parsing a JSON string
Error parsing JSON request string
Searching google images from java code
Reading Nested Json in Java