我得到这个json响应调用REST api:
{
"ProfileResponse": {
"Request_timestamp": 1378473780145780000,
"Execution_time": 30135057
},
"Results": {
"newsession": {
"Sessionid": "110873298014",
"Status": "ACTIVE",
"Tag": "GO",
"TimeStamp": 1378473780146026000
}
},
"ResultsCount": 0,
"ResultsURL": ""
}
我希望解析此响应并将newsession
放入已定义为objective-c类的会话对象中。
我定义了一个映射基本字段的base_mapping
('PrifileResponse','Results','ResultsCount','ResultsURL'),以及另一个'newsession'映射和关系映射:
RKObjectMapping *baseResponseMapping = [RKObjectMapping mappingForClass:[CSBaseResponse class]];
RKObjectMapping *sessionMapping = [RKObjectMapping mappingForClass:[CSSessionResponse class]];
[sessionMapping addAttributeMappingsFromDictionary:@{
@"Sessionid": @"sessionid",
@"Status": @"status"
}
];
RKRelationshipMapping *relationshipMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"Results" toKeyPath:@"results" withMapping:sessionMapping];
[baseResponseMapping addPropertyMapping:relationshipMapping];
但我无法访问“newsession”,
我的问题具体是,是否有一种语法我可以在“来自关键路径”中使用,如Results.newsession
或类似的东西来访问“newsession”的内部,
或解析/映射此嵌套结构的最佳做法是什么?