我得到这个调用 REST api 的 json 响应:
{
"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”的内部,
或者解析/映射这个嵌套结构的最佳实践是什么?