0

I am trying to convert string like this:

{"Shops":[
{"city":"Riga","shops":[{"a":"some info here","b":"...","c":"..."},{"a":"some info here","b":"...","c":"..."}]},{"city":"Liepaja","shops":[{"a":"info here","b":"info....","c":"..."}]
]}

to 2d array, like

shops[0][0]=>{"a":"some info here","b":"...","c":"..."}
shops[1][0]=>{"a":"info here","b":"info....","c":"..."}

Is it possible? Is there some easy way to do that?

I've searched, tried, but I still don't know how to do that. I'm new in java.

5
  • 1
    It's very hard to see what is exactly you want to do. Please format your code to make it clear and clarify how these two array entries relate to the original string. Commented Nov 14, 2013 at 21:51
  • Are you sure this is java? It looks like javascript... Commented Nov 14, 2013 at 21:52
  • Take a look at the JSON processing API. Commented Nov 14, 2013 at 21:52
  • It would probably be better for you to make a City object that has within it a list of shops. It would make more sense and be easier to handle than a 2d array, and you won't lose the city names, as you currently are with the 2d array. Commented Nov 14, 2013 at 21:53
  • Thanks! I was stuck here almost 4 days.. And it turns out to be so easy.. :D Commented Nov 14, 2013 at 22:03

3 Answers 3

1

That is a JSON string. There are a number of libraries that will do this for you.

Sign up to request clarification or add additional context in comments.

Comments

0

That looks like JSON data, and you should treat it as such.

Try a JSON parsing library for Java. I like GSON for its simplicity. Take a look at the Gson.fromJson() set of methods.

Comments

0

The type of data you have posted is JSON encoded. you could use a json encoder and decoder to do this job easily.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.