Can someone explain mapping Restkit Get results mapping into an Array

I've been through the available documentation including https://github.com/RestKit/RestKit/wiki/Object-mapping and I haven't been able to find an explanation or examples to map GET results in

  • (void)objectLoader:(RKObjectLoader*)objectLoader didLoadObjects:(NSArray*)objects
  • What exactly is (NSArray*)objects ?

    When I returned just one JSON object from the server I was able to map it with :

    NSString *bodyResults;
    bodyResults = [[objectLoader response] bodyAsString];
    
    NSDictionary *resultsDictionary = [bodyResults objectFromJSONString];
    
    NSString *subject = [resultsDictionary  objectForKey:@"subject"];
    

    But now that i'm returning a JSON list (a selection of objects) I'm having trouble.

    I'm mapped the object before submitting the get:

    //map offering RKObjectMapping* offeringMapping = [RKObjectMapping mappingForClass:[Offering class]]; [offeringMapping mapKeyPath:@"categoryId" toAttribute:@"categoryId"]; [offeringMapping mapKeyPath:@"merchantId" toAttribute:@"merchantId"]; [offeringMapping mapKeyPath:@"name" toAttribute:@"name"]; [offeringMapping mapKeyPath:@"latitude" toAttribute:@"latitude"]; [offeringMapping mapKeyPath:@"longitude" toAttribute:@"longitude"];

    [[RKObjectManager sharedManager].mappingProvider setMapping:offeringMapping forKeyPath:@"offering"];
    
    double latitude = [(AppDelegate*)[[UIApplication sharedApplication] delegate] currentLatitude];
    double longitude = [(AppDelegate*)[[UIApplication sharedApplication] delegate] currentLongitude];
    
    
    NSString *latitudeString = [[NSNumber numberWithDouble:latitude] stringValue];
    NSString *longitudeString = [[NSNumber numberWithDouble:longitude] stringValue];
    
    NSDictionary *getParams = [NSDictionary dictionaryWithKeysAndObjects:
                                @"lat",latitudeString,
                                @"long",longitudeString,
                                nil];
    
    [[RKObjectManager sharedManager] loadObjectsAtResourcePath:[@"/merchantofferings" stringByAppendingQueryParameters:getParams] delegate:self];
    

    Thanks


    In response to your first question, (NSArray *)objects is an array of the objects that were loaded by the objectLoader. So in your case, they should be objects of type Offering populated with the attributes that you mapped in the object mapping.

    Do you have a sample of the JSON that you're returning from the GET request that you can post here? Are you sure that it's valid JSON and is being returned exactly as you anticipate?

    链接地址: http://www.djcxy.com/p/49194.html

    上一篇: 使用RestKit将NSArray映射到具有动态嵌套属性的JSON?

    下一篇: 有人可以解释映射Restkit获取结果映射到数组