我正在尝试使用boon jsonfactory解析我的类中的列表属性列表,但输出是一个空列表。
class Test {
List<List<String>> id;
public List<List<String>> getId() {
return id;
}
public void setId(List<List<String>> id) {
this.id = id;
}
@Override
public String toString() {
return id.toString();
}
}
String myinput = "{ \"id\": [[\"INPUTID\"]]}";
Test receivedAdLogObj = JsonFactory.create().fromJson(myinput, Test.class);
System.out.println(receivedAdLogObj.toString());上述程序的输出为
如何解析json中的字符串列表??
发布于 2016-02-28 20:54:57
根据一些快速测试,这似乎是Boon JSON库的一个限制。它似乎可以很好地处理具有一个泛型级别的字段(即List<String>),但它似乎不喜欢像您的List<List<String>>那样的更多嵌套结构。
使用Gson或Jackson,您的示例可以很好地工作:
System.out.println(new Gson().fromJson(myinput, Test.class));
System.out.println(new ObjectMapper().readValue(myinput, Test.class));两者都会打印预期的输出:
[[INPUTID]]因此,如果可能的话,我可能会建议迁移到这两个库中的一个。
https://stackoverflow.com/questions/35612058
复制相似问题