【发布时间】:2016-08-10 08:32:48
【问题描述】:
我正在构建一个可以离线工作的应用程序。
我将 json 下载到 sdcard 中的文件中。然后当我尝试使用 gson 加载它并将它与 POJO 类映射时,我得到错误:
读取文件:
File newList = new File(rootFolder.getParent(), "custom_list.new.dat");
String customListStr = Utils.readTextFile(newList);
public static String readTextFile(File file) throws IOException {
FileInputStream reader = new FileInputStream(file);
StringBuffer data = new StringBuffer("");
byte[] buffer = new byte[1024];
while (reader.read(buffer) != -1)
data.append(new String(buffer));
reader.close();
return data.toString();
}
try to load it
//Load json file to Model
Gson gson = new GsonBuilder().create();
final MoviePojo response = gson.fromJson(customListStr, MoviePojo.class);
int size = response.getContentList().size();
:错误:com.google.gson.stream.MalformedJsonException:使用 JsonReader.setLenient(true) 在第 1 行第 3205 列路径 $ 接受格式错误的 JSON
【问题讨论】:
标签: java android json gson retrofit