핵심 데이터 모델과 함께 사용할 json 응답을 구문 분석하려고합니다. 나는 계속됩니다 엔티티라는 이름의 프로그램과 일대 다 관계 채널 ID를 개최한다 채널라는 이름의 실체가 어디 CoreData이를 얻을 필요가Rest to many many to many relationships 생성하기
{
"@context": "TVSchedule",
"ReturnCode": "0",
"ReturnMessage": "Successful request",
"Channel": [
{
"ChannelId": "http%…..0",
"Program": [
{
"@programId": "http……..",
"Title": "Divorce Court",
"ProgramLogo": "http://00_180x101.png",
"ProgramLogos": [
{
"@size": "small",
"#text": "http://.png"
},
{
"@size": "large",
"#text": "191.png"
}
],
"ProgramDetailsURL": "http:9",
"PublishedStartTime": "2013-07-01T19:00:00",
"PublishedEndTime": "2013-07-01T19:30:00",
"Duration": "00:00:30:00",
"RatingInfo": {
"@system": "MPAA",
"@code": "TV-PG",
"@age": "10",
"Title": "Not recommended for children under 10 years",
"Logo": "http://"
},
"ShortDescription": "She says she cannot trust him .",
"Year": "2013",
"Genres": [
"Series",
"Reality",
"Public Affairs",
"News",
"Episodic"
]
},
:이 json으로의 샘플입니다 그 레벨에있는 속성의 목록이며 엔티티와 많은 관계를 맺을 것입니다 ProgramLogo (json 파일의 "ProgramLogos") 장르 (장르 문자열 배열은 하나의 문자열 속성 만 포함하는 여러 장르 엔티티로 추가됩니다), RatingsInfo 엔티티 (해당 사전과 일대일 관계), 모든 프로그램에 RatingsInfo가 표시되지 않습니다 ...
다음은 내가 사용하는 RestKit 코드입니다.
RKEntityMapping *channelMapping = [RKEntityMapping mappingForEntityForName:kCDChannelEntity inManagedObjectStore:managedObjectStore];
channelMapping.identificationAttributes = @[ kCDChannelId ];
[channelMapping addAttributeMappingsFromDictionary:@{
kJsonChannelId : kCDChannelId
}];
RKEntityMapping *programMapping = [RKEntityMapping mappingForEntityForName:kCDProgramEntity inManagedObjectStore:managedObjectStore];
[programMapping addAttributeMappingsFromDictionary:@{
@"@programId" : kCDProgramId ,
@"ProgramLogo" : kCDProgramLogo,
@"ProgramDetailsURL" : kCDProgramDetailsUrl,
@"Duration" : kCDProgramDuration,
@"PublishedStartTime" : kCDProgramStartTime,
@"PublishedEndTime" : kCDProgramEndTime,
@"Title" : kCDProgramTitle,
@"Year" : kCDProgramYear,
@"ShortDescription" : kCDProgramShortDescription
}];
[RKObjectMapping addDefaultDateFormatterForString:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'" inTimeZone:nil];
[channelMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Program" toKeyPath:kCDChannelHasProgramsRel withMapping:programMapping]];// ??
RKEntityMapping *parentalRatingMapping = [RKEntityMapping mappingForEntityForName:kCDParentalRatingEntity inManagedObjectStore:managedObjectStore];
[parentalRatingMapping addAttributeMappingsFromDictionary:@{
@"[email protected]": kCDParentalRatingAge,
@"[email protected]" : kCDParentalRatingCode,
@"Program.RatingsInfo.Logo" : kCDParentalRatingLogo,
@"[email protected]" : kCDParentalRatingSystem,
@"Program.RatingsInfo.Title" : kCDParentalRatingTitle}];
[programMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Program.RatingsInfo" toKeyPath:kCDProgramHasParentalRatingRel withMapping:parentalRatingMapping]];// ??
RKEntityMapping *genresMapping = [RKEntityMapping mappingForEntityForName:kCDGenreEntity inManagedObjectStore:managedObjectStore];
[genresMapping addAttributeMappingsFromDictionary:@{
@"Program.Genres": kCDGenreName
}];
[programMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"Program.Genres" toKeyPath:kCDProgramHasGenres withMapping:genresMapping]];
RKEntityMapping *logoMapping = [RKEntityMapping mappingForEntityForName:kCDProgramLogoEntity inManagedObjectStore:managedObjectStore];
[logoMapping addAttributeMappingsFromDictionary:@{
@"[email protected]" : kCDLogoSize,
@"Program.ProgramLogos.#text" : kCDLogoText
}];
좋아, 지금이 두 가지 문제 : 1)이 비 KVO 배열 분석 (장르, 다른 엔티티의 각 문자열을, 그리고 ProgramLogos (A 법인의 각 DICT)하는 방법
2) RestKit은 programId (키 "@programId")를 구문 분석하지 않습니다 이유는 무엇입니까? 키의 "@"는 구문 분석을 중지합니까?
나는 그것과 같은
*** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFDictionary 0x958f980> valueForUndefinedKey:]: this class is not key value coding-compliant for the key programId.'
그게 내가 생각하기에 ... 나는 keyPaths에 대해 잘 모르겠다 ... 어떻게 임베디드 오브젝트와 관계를 위해 만들어 지는가? – user426132
예를 들어 주시겠습니까? – user426132
엔티티 자체의 응답 설명자가 필요하지 않습니까? – user426132