android Jackson用JSONArrays解析

时间:2015-04-09 15:49:48

标签: android json jackson

所以我真的没有看到我在使用JSON解析时遇到了什么问题。它不会解析JSONArrays。我已经使用常规的JSON对象测试它并且它工作正常但是数组似乎将它绊倒

这是我的JSON文件

    {
    "list": [
        {
            "field_one": "HI",
            "field_two": "Hi, AGAIN"
        },
        {
            "field_one": "hola",
            "field_two": "konnbanwa"
        }
    ]
}

这是我将JSON数据放在

中的类
public class Test implements Serializable {
public ArrayList<List> list;

public ArrayList<List> getList() {
    return list;
}

public void setList(ArrayList<List> list) {
    this.list = list;
}

public class List implements Serializable {
    public String field_one;
    public String field_two;

    public String getField_one() {
        return field_one;
    }

    public void setField_one(String field_one) {
        this.field_one = field_one;
    }

    public String getField_two() {
        return field_two;
    }

    public void setField_two(String field_two) {
        this.field_two = field_two;
    }


   }
}

这是我将值映射到班级的地方....

ObjectMapper mapper = new ObjectMapper();
        mapper.setVisibilityChecker(
                mapper.getVisibilityChecker()
                        .withFieldVisibility(JsonAutoDetect.Visibility.ANY));
        Test test = mapper.readValue(json, Test.class);

0 个答案:

没有答案