将有效Json请求转换为ArrayList

时间:2013-02-06 12:35:13

标签: java json

我有一个有效的json,如图所示

{

    "Items": "{one,two,three}"
}

我需要使用ObjectMapper将其映射到ArrayList。

但它没有设定价值,请告诉我。

我试过这种方式

public class Hi {
    private static JsonHelper jsonHelper = JsonHelper.getInstance();

    public static void main(String[] args) throws Exception {

        ObjectMapper mapper = new ObjectMapper();
        MyList yourData = mapper.readValue(new File("yourdata.json"),
                MyList.class);

    }

}


public class MyList {

    private ArrayList<String> Items= new ArrayList<String>();
    // setters and getters 

}

2 个答案:

答案 0 :(得分:2)

“{one,two,three}”不代表json中的列表。 [“one”,“two”,“three”]是三个元素的列表。

答案 1 :(得分:0)

json如下

{     “测试一下”,     “项目”:[“一个”,“两个”,“三个”] }