android - realm怎样支持hashmap
天蓬老师
天蓬老师 2017-04-17 17:48:43
0
1
476

realm不支持hashmap这种形式
stackoverflow给出了解决方案
http://stackoverflow.com/ques...

class MyData extends RealmObject {
    private RealmList<MyMap> myMap;
}

class MyMap extends RealmObject {
    private String key;
    private MyClass value;
}

但是我用gson解析时会报错
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2656 path $.layers[0].icons
因为map是一个对象,而private RealmList<MyMap> myMap;是一个数组
应该怎样解析呢?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(1)
小葫芦

If you convert Map<String, MyClass> into RealmList<MyMap>
you also need to change the returned json format. You need to change the format of {myMap: {key1: value1, key2: value2}} to

{myMap: [

{key: key1, value: value1},
{key: key2, value: value2}

]
}

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template