(android)How to use gson get data from JSON

In main class.I can’t use “List posts = results.getPosts();” .How should I do?

main class

private void showData(String jsonString) {
    Gson gson = new Gson();
    Blog1 blog = gson.fromJson(jsonString, Blog1.class);
    List<Result> results = blog.getResults();
    List<Post1> posts = results.getPosts();
    mAdapter = new CustomAdapter1(this, posts);

Blog1 class

public class Blog1 {
String success;
List<Result> results;

public List<Result> getResults() {
    return results;

Result class

public class Result {
String name;
public String getName() {
    return name;
List<Post1> posts;
public List<Post1> getPosts() {
    return posts;

Post1 class

public class Post1 {
String name;
public String getName() {
    return name;

Source: json

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.