0

I have mapping case with array of elements for specific field as the below example.I made relationship between Hotel & amenities but i can't get the values (A,B,C) because it didn't have identifier name.What is the correct value can set it in XXX to do mapping for name

JSON :

 "hotel":{
 property_amenities":["A","B","C"]
 }

Mapping :
 [hotelDetailEntityMapping addAttributeMappingsFromDictionary:@{
@"XXX"               : @"name", 
}];
wod
  • 812
  • 1
  • 10
  • 23

3 Answers3

0

Assuming it's deserialized:

NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingMutableContainers error: &error];

dict[@"property_amenities"][0] -> A

dict[@"property_amenities"][1] -> B
Grzegorz Krukowski
  • 18,081
  • 5
  • 50
  • 71
0

I guess you want to get A, B and C, Then you'll need to do this:

//Assume you have in a NSDicionary dictionary your JSON, then:
NSArray * propertyAmenities = dictionary[@"property_amenities"];

NSLog(@"%@", propertyAmenities[0])); // You get A

Editted:

If you haven't had you json in a nsdictionary, take a look of the answer below of mine from @Grzegorz Krukowski

Alex
  • 1,061
  • 10
  • 14
0

I have found the solution as the below code.

This is correct mapping : [hotelDetailEntityMapping addPropertyMapping:[RKAttributeMapping attributeMappingFromKeyPath:nil toKeyPath:@"name"]];

wod
  • 812
  • 1
  • 10
  • 23