栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Gson List的反序列化 进入realmList

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Gson List的反序列化 进入realmList

错误消息“

Expected a string but wasNAME
”可以通过检索
JsonReader
实际json对象之前的json对象的名称(
String
在您的情况下为)来解决。

您可以看一下JsonReader的Android文档。它具有详细的说明和代码段。您也可以

readMessage
在文档的示例代码片段中查看该方法。

我已经将您的

read
方法修改为我认为的样子。 注意: 我没有测试代码,因此其中可能存在一些小错误。

@Overridepublic RealmPerson read(JsonReader in) throws IOException {    RealmPerson rList = new RealmPerson();    in.beginObject();    String name = "";    while (in.hasNext()) {        name = in.nextName();        if (name.equals("userId")) { String userId = in.nextString(); // update rList here         } else if (name.equals("otherStuff")) { // since otherStuff is a RealmList of RealmStrings, // your json data would be an array // You would need to loop through the array to retrieve  // the json objects in.beginArray(); while (in.hasNext()) {     // begin each object in the array     in.beginObject();     name = in.nextName();     // the RealmString object has just one property called "value"     // (according to the pre snippet in your question)     if (name.equals("val")) {         String val = in.nextString();          // update rList here      } else {         in.skipValue();     }     in.endObject(); } in.endArray();        } else { in.skipValue();        }    }    in.endObject();    return rList;}

让我知道是否有帮助。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/486629.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号