Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am writing my first Gson sample. Now I know how to parse basic JsonObject / JsonArray like as below.

Successful JSON sample:

   { "name":"A",
      "title":[ {"name":"B"},
                {"name":"C"}]
    }

Class code:

public class Person {
    private String name;
    private ArrayList<Name> title;

    public Person(){
    }

    public String getname(){
        return name;
    }

    public void setname(String name){
        this.name = name;
    }
    public ArrayList<Name> getTitle(){
        return title;
    }

    public void setTitle(ArrayList<Name> title) {
        this.title = title;
    }
}

public class Name{
    private String name;

    public String getname(){
        return name;
    }

    public void setname(String name){
        this.name = name;
    }
}

Jave code:

Gson gson = new Gson();
Person result = gson.fromJson("JSONString", Person.class);  

But now I have this Nested Json, I don't know how to distinguish private ArrayList <Name> in Class Person. Use JAVA interface?TypeAdapter?

{ "name":"A",
  "title":[ {"name":"B"},
            {"name":"C",
             "title":["name":"a","name":"b"]
            },
            {"name":"D"},
            {"name":"E",
              "title":["name":"a","name":"b"]
            }
          ]
}
share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.