【发布时间】:2015-09-01 17:29:20
【问题描述】:
我使用 GSON 库读取了一个 json 文件。 我使用以下代码:
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonParser jp = new JsonParser();
JsonElement je = jp.parse(uglyJSONString);
String prettyJsonString = gson.toJson(je);
一切正常,如果我的 json 包含所有值,但如果 json 中缺少某些值,例如以下 json,我会得到一个异常。
com.google.gson.stream.MalformedJsonException:
Expected value at line 1 column 217 path $.repeatInterval
.
{
"key1": "a",
"key2": "",
"key3":
}
使用 GSON 库时如何读取缺失值的 json 文件?
编辑: 无一例外的解决。添加“key3:””
{
"key1": "a",
"key2": "",
"key3": ""
}
【问题讨论】: