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]
2
  • Can you clear up your question? Your example data does not have consistent information in it. Commented Oct 14, 2014 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. Commented Oct 14, 2014 at 10:23

3 Answers 3

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.

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

Comments

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

Comments

0

use Google gson

Create Object with necessary variable and parse json string.

Your answer How to use fromGson with arrays

Comments

Your Answer

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