0

I want to parse array inside object through GSON.. for Example

{
  'title': 'Java Puzzlers: Traps, Pitfalls, and Corner Cases',
  'isbn': '032133678X',
  'authors':[
    {
      'id': 1,
      'name': 'Joshua Bloch'
    },
    {
      'id': 2,
      'name': 'Neal Gafter'
    }
  ]
}

I am only able to parse only object i.e. title, ISBN and got its value but i don't know how to get the value of authors? Please help ,I am using JSON parsing through GSON in android..

1

2 Answers 2

0
ArrayList<Authors> lAuthors = new ArrayList<Authors>();
List<Authors> list = new Gson().fromJson(json, lAuthors.getClass());

for (Object a : list)
{
   System.out.println(a);
}

This will give you values in class Author's object.

public class Author{

    int id;
    String name;
    //getter setter here
}

Hope it helps.

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

2 Comments

its okay if there is object inside array but what about other object which is outside Author
You can have class as per your json response structure. Check this and this. this, too. :) @dheeraj92
0

those are usefull links for Nasted JSON parsing examples :

Parsing JSON nested array with GSON on Android

http://www.javacreed.com/simple-gson-example/

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.