I have a json data that I need to be parse in java
The data is in the form
["string1","string2","string3",...]
Any idea how I can do that?
asked Feb 17, 2012 at 13:15
Waheed Khan
1,3217 gold badges18 silver badges28 bronze badges
-
possible duplicate of A better Java JSON library?Bart Kiers– Bart Kiers2012年02月17日 13:20:52 +00:00Commented Feb 17, 2012 at 13:20
-
See also stackoverflow.com/questions/2635982/parsing-json-in-javaDNA– DNA2012年02月17日 13:25:30 +00:00Commented Feb 17, 2012 at 13:25
3 Answers 3
You can use JacksonJSON. For a good tutorial, have a look here.
answered Feb 17, 2012 at 13:20
Sapan Diwakar
11k6 gold badges35 silver badges43 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You can use GSON api and use the code as below
Type type = new TypeToken<Collection<String>>(){}.getType();
List<String> results = new Gson().fromJson(json, type);
answered Feb 17, 2012 at 13:19
Sandeep Nair
3,6604 gold badges28 silver badges42 bronze badges
Comments
It depends a bit on how complete you want toe JSON parsing to be. If the above example is representative of all you expect, you might as well do some good old string parsing with indexOf and split.
If you want more complete JSON parsing, I'd suggest looking at the official json.org site and their Java page
answered Feb 17, 2012 at 13:23
Frank van Puffelen
604k85 gold badges896 silver badges869 bronze badges
Comments
lang-java