0

I want to make it so I can use "." to obtain values within a Map within the main Map in a JSON file.

E.g. My file looks like this: http://pastie.org/private/wl6jhgnylevz2fdcncyjrg

And in Java, I load the configuration to a Map (but I can always use JSONObject if necessary to do the following). But I want to get the value of "One" in the "Test" map using a get method that allows me to type: config.get("Test.One");

Here's what I currently have: http://pastie.org/private/zkxbxgs2nsteb1g0zcp6tq

It just doesn't make sense (what I wrote), doesn't work and I pretty much just wrote a load of crap. I'm really confused as to how to do this, any help would be appreciated. I'm using JSON-Simple.

Faris Rehman
  • 129
  • 1
  • 4
  • 11

1 Answers1

1

Have you considered using a 3rd party libraries like Json.org or Gson to serialize/deserialize your object into/from json?

That way you forget about the hassle of managinf strings and JSons and just use objects straight up. I dont know if you'll get the path you are looking for you out of the box should easily achieve something like config.test.one.

jirungaray
  • 1,674
  • 1
  • 11
  • 18
  • GSON sounds good, thank you! I've used GSON in the past for other projects but I just found it a bit more tricky to use relative to JSON-Simple, but I guess I can understand it more now. – Faris Rehman May 03 '15 at 15:50
  • 1
    like all these kind of libs it might be a pain to setup the first object, but as your project grows that effort will pay off multiple times. – jirungaray May 03 '15 at 15:53