日期:2014-05-20 浏览次数:20849 次
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
// file是一个保存json格式数据的文件。
// file文件内容: [{"code": "2","content": "2222","createTime": null},{"code": "1","content": "sfsdf","createTime": 123132}]
String jsonStr = FileUtils.readFileToString(file);
// Catalog为实体类,属性为code, content, createTime
Catalog catalog = gson.fromJson(jsonStr, Catalog.class);// 报错:java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2