解析嵌套的JSON数据,并保存到nadroid中的Realm DB中

时间:2016-12-05 07:53:20

标签: android realm

我是Android和Realm DB的新手。我没有得到如何解析嵌套的JSON数据并保存到Realm

我有JSON数组 -

[{ _id: 583d45e1ee31662334c0d63e,
senderUsername: '7411271012',
senderUserId: '4',
senderDisplayName: 'Santosh',
messages: '',
sendDate: 'November 29th 2016, 2:39:53 pm',
groupId: '1',
groupName: 
 { groupName: 'XYZ Support',
   GroupDisplayName: 'XYZZ Support' },
category: 'UtoG',
messageType: 'message',
fileName: '',
__v: 0 } ]

我创建了两个模型类

public class **myChatFeed** extends RealmObject {
@PrimaryKey
private String _id;
private String senderUsername;
private String senderUserId;
private String senderDisplayName;
private String messages;
private String sendDate;
private String groupId;
private groupNames groupName;
private String category;
private String messageType;
private String fileName;
private String __v;
> Getter and Setters >

}

public class **groupNames** extends RealmObject {

private String groupName;
private String GroupDisplayName;
<>Getters and Setters<>

}

这是插入Realm的代码

realm.beginTransaction();           
realm.createOrUpdateAllFromJson(myChatFeed.class,jsonArrayData);
realm.commitTransaction();

当我执行此操作时,内部JSON对象将不会保存 显示o / p:groupName:null,其中所有其他字段都被保存。

任何帮助../??

0 个答案:

没有答案