Doctor 클래스 안에 RealmList- specializationList가 있습니다.
public class Doctor extends RealmObject {
@PrimaryKey
private String doctorId;
private FullName fullName;
private Age age;
private String organizationId;
private Position position;
private String category;
private String loyalty;
private RealmList<Specialization> specializationList;
private Contacts contacts;
private String key;
....
전문화 클래스
public class Specialization extends RealmObject{
private String specializationName;
...
의사 JSON :
[
{
"doctorId": "7d8e72d7-809b-4273-9a3f-fa21718dee7f",
"doctorFullName": {
"firstName": "FirstName0",
"lastName": "LastName0",
"middleName": "MiddleName0"
},
"doctorPosition": {
"positionName": "PositionName0",
"department": "Department0"
},
"organizationId": "7cfaf5c0-127a-4cfc-b73b-52a35fd02ffd",
"specializations": [
{
"specializationName": "Specialization name 3"
},
{
"specializationName": "Specialization name 2"
},
{
"specializationName": "Specialization name 1"
}
],
"key": "firstname0 middlename0 lastname0"
}
]
createOrUpdateAllFromJson 메서드를 사용하여 JSON 구문 분석 :
realm.createOrUpdateAllFromJson(Doctor.class, json);
내가하려는 것은 의사 객체 에서 RealmList를 얻는 것입니다 .
RealmList<Specialization> specializationList = doctor.getSpecializationList();
그러나 specializationList의 크기는 0입니다.
Realm 문서 : 일부 JSON API는 Realm이 아직 지원하지 않는 정수 나 문자열과 같은 기본 유형의 배열을 반환합니다 .
createOrUpdateAllFromJson을 사용하여 JSON 배열 (특수화)을 구문 분석 할 수 있습니까?
네, Realm은 그것을 파싱 할 수있을 것입니다.하지만 당신의 이름이 올바르지 않은 것 같습니다. Doctor 클래스에서 호출 specializationList
하지만 JSON에서는 specializations
.
Doctor 클래스를 다음과 같이 변경하면 작동합니다.
public class Doctor extends RealmObject {
@PrimaryKey
private String doctorId;
private FullName fullName;
private Age age;
private String organizationId;
private Position position;
private String category;
private String loyalty;
private RealmList<Specialization> specializations;
private Contacts contacts;
private String key;
....
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다