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;是一个数组
应该怎样解析呢?
高洛峰2017-04-17 17:50:43
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}
]
}