Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 带XML的RestKit-将代码转换为0.20_Ios_Objective C_Restkit_Restkit 0.20 - Fatal编程技术网

Ios 带XML的RestKit-将代码转换为0.20

Ios 带XML的RestKit-将代码转换为0.20,ios,objective-c,restkit,restkit-0.20,Ios,Objective C,Restkit,Restkit 0.20,对于RestKit 0.20,以下代码的等效语法是什么 RKObjectMapping *atozMapping = [RKObjectMapping mappingForClass:[Atoz class]]; [atozMapping mapKeyPath:@"" toAttribute:@"city"]; RKObjectMapping *genreMapping = [RKObjectMapping mappingForClass:[Genres class]]; [genreMapp

对于RestKit 0.20,以下代码的等效语法是什么

RKObjectMapping *atozMapping = [RKObjectMapping mappingForClass:[Atoz class]];
[atozMapping mapKeyPath:@"" toAttribute:@"city"];

RKObjectMapping *genreMapping = [RKObjectMapping mappingForClass:[Genres class]];
[genreMapping mapKeyPath:@"" toAttribute:@"genre"];

RKObjectMapping *stationSearchMapping = [RKObjectMapping mappingForClass:[StationSearchData class]];
[stationSearchMapping mapKeyPathsToAttributes:@"location", @"location", @"city", @"city", @"latitude", @"latitude", @"longitude", @"longitude", nil];
[stationSearchMapping mapKeyPath:@"browseatoz.atoz" toRelationship:@"browseAtozArray" withMapping:atozMapping];
[stationSearchMapping mapKeyPath:@"genres.genre" toRelationship:@"genreArray" withMapping:genreMapping];

[stationMapping mapRelationship:@"stationSearchData" withMapping:stationSearchMapping];
[stationManager.mappingProvider setMapping:stationSearchMapping forKeyPath:@"stationSearchData"];
以下是我尝试过的,但它似乎没有正确加载browseAtozArray(city为空)和genreArray(流派为空):

RKObjectMapping *atozMapping = [RKObjectMapping mappingForClass:[Atoz class]];
[atozMapping addAttributeMappingsFromDictionary:@{
                                                      @"": @"city",
                                                      }];

RKObjectMapping *genreMapping = [RKObjectMapping mappingForClass:[Genres class]];
[genreMapping addAttributeMappingsFromDictionary:@{
                                                  @"": @"genre",
                                                  }];

RKObjectMapping *stationSearchMapping = [RKObjectMapping mappingForClass:[StationSearchData class]];
[stationSearchMapping addAttributeMappingsFromDictionary:@{
                                                  @"location.text": @"location",
                                                  @"city.text": @"city",
                                                  @"latitude.text": @"latitude",
                                                  @"longitude.text": @"longitude"
                                                  }];
RKRelationshipMapping* relationShipatozMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"browseatoz.atoz" toKeyPath:@"browseAtozArray" withMapping:atozMapping];
[stationSearchMapping addPropertyMapping:relationShipatozMapping];
RKRelationshipMapping* relationShipGenresMapping = [RKRelationshipMapping relationshipMappingFromKeyPath:@"genres.genre" toKeyPath:@"genreArray" withMapping:genreMapping];
[stationSearchMapping addPropertyMapping:relationShipGenresMapping];

[stationMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"stationSearchData" toKeyPath:@"stationSearchData" withMapping:stationSearchMapping]];

[stationManager addResponseDescriptor: [RKResponseDescriptor responseDescriptorWithMapping:stationSearchMapping method:RKRequestMethodGET pathPattern:nil keyPath:@"stationSearchData" statusCodes:[NSIndexSet indexSetWithIndex:200]]];
下面是相关的XML:

<stationSearchData>
   <location>
  <![CDATA[ 79605 ]]>
 </location>
 <city>
  <![CDATA[ Abilene ]]>
 </city>
 <latitude>
  <![CDATA[ 32.43892288 ]]>
 </latitude>
 <longitude>
  <![CDATA[ -99.77902222 ]]>
 </longitude>
 <browseatoz>
  <atoz>
   <![CDATA[ Abilene ]]>
  </atoz>
  <atoz>
   <![CDATA[ Texas ]]>
  </atoz>
 </browseatoz>
 <genres>
  <genre>
   <![CDATA[ Rock ]]>
  </genre>
 </genres>
 <personalities/>
</stationSearchData>


我不太会使用XML,但会尝试使用无键路径映射:

[genreMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"genre"]];

谢谢你,韦恩。这让我更进一步了,但现在我看到了一些关于这些值的消息,如:E restkit.object_mapping:RKMappingOperation.m:440将keyPath'(null)处的值转换为'NSString'类型的表示失败:Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002“值转换失败”{text=Abilene;}'到NSString:咨询的2个值转换器均未成功。“UserInfo=0x15af2970{detailedErrors=(“Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002\”给定的值还不是一个…我想我需要将“.text”应用到nil键路径,有什么想法吗?像这样?[genreMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@“@text”toKeyPath:@“流派”];当我将其更改为该选项时,它会崩溃。呜呜,它现在可以工作了:[genreMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:@“text”toKeyPath:@“流派”];忘了为此感谢您了..所以谢谢您!没有太多关于最新RestKit和解析XML的信息。