0

String result = "{"results":[{"IsRecommended":null,"BadgesOrder":[10,20,aa]},{"IsRecommended":false,"BadgesOrder":[30,40.bb]}]}";

How to split the string in such a way, it should hold the values in the string when it is passed to csv library it prints out the contents to csv in the below pattern.

IsRecommended BadgesOrder 
null [10,20,aa]
false [30,5,bb]
  • Can you clear up your question? Your example data does not have consistent information in it. – vincent Oct 14 '14 at 10:00
  • 1
    I want to store the output in a string, when the string is passed to csv library it prints out the contents to csv in the above manner. –  Oct 14 '14 at 10:23

3 Answers3

1

I would recommend using a JSON-Parser Library like Jackson to do the Job. There is a method readValue() of the ObjectMapper, which does the unmarshalling back to an object. If you have a proper Java-Object-representation of the results, Jackson would do the job.

Thomas Junk
  • 5,588
  • 2
  • 30
  • 43
0

what kind of result do you want, just string in the array? If you want to do it perfectly , you must use the jsonlib, like fastjson ext. it will solve the special characters and type problem.

In your case, you just want the string type,you should deal with type cast by yourself. 1. you can save the date type array in your json string 2. you also can define a class to map the array

Feng Lin
  • 670
  • 4
  • 8
0

use Google gson

Create Object with necessary variable and parse json string.

Your answer How to use fromGson with arrays

Community
  • 1
  • 1
Mikhail
  • 2,690
  • 4
  • 28
  • 43