2

How to convert a JSON which is a combination of String and an Array,please suggest how to do that with a code,suppose we have the following JSON

{"status":"true","results":[{"name":"Sudini  "},{"name":"Bimal"}]}
0

3 Answers 3

1

Take a look at gson, a google library to serialize / unserialize java objects into json.

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

Comments

1

If you're willing to use third party libraries, Jackson and Gson are two popular solutions that will perform data binding for you.

Comments

1

If you do this in GSON:

public class Something{
  @SerializedName("status")
  private boolean status;
  @SerializedName("results")
  private List<Result> results;

  // accessor and mutator 

}

public class Result{
  @SerializedName("name")
  private String name;

  // accessor and mutator 
}


public class App {
    public static void main(String[] args) {
        Gson gson = new Gson();
        String jsonString = // your json string 

        Something obj = (Something) gson.fromJson(jsonString, Something.class);

        System.out.println(obj.getResults().get(1).getName());

    }
}

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.