Sunday 15 June 2014

objective c - Restkit NSString includes metadata -


I have a JSON file that I am downloading from the web and parsing using the restkit. My problem is that I have an array of strings in which I am trying to map to my object. For some reason, while parsing that string, it ends with a description of the metadata object in the string. Please see my code snippet below which I am currently using, and I am experiencing errors I note: I removed any core data integration and removed my test as bare bones, Could try to track

Object interface

  @interface BLAuthor: NSObject @property (nonatomic, retain) NSString * name; @ Nd @ interface BLVLume: NSBKect @ property (nanatomic, titan) nsstaining * id; @protecti (nontomic, titan) nset * author; @end   

Mapping and request operation

  RKObjectMapping * volumeMapping = [RKObjectMapping mappingForClass: [BLVolume class]]; [VolumeMapping addAttributeMappingsFromDictionary: @ {@ "ID": @ "id"}]; RK object mapping * authorMapping = [RK objectmapping mapping forex: [blaster class]]; [AuthorMapping addPropertyMapping: [RKAtiting Mapping Feature MappingFrom Path: Zero by Path: @ "Name"]]; [VolumeMapping addPropertyMapping: [RKRelationshipMapping relationshipMappingFromKeyPath: @ "volumeInfo.authors" toKeyPath: @ "Author" withMapping: authorMapping]]; NSIndexSet * statusCodes = RKStatusCodeIndexSetForClass (RKStatusCodeClassSuccessful); RKResponseDescriptor * responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping: volumeMapping pathPattern: zero main path: @ "item" statusCodes: statusCodes]; NSURLRequest * Request = [NSRR request request with url: [NSURL URLWithString: @ "https://example.com/?q=123"]]; RK ObjectRequest Operation * Operation = [[RK ObjectRaest Operation Alok] In With Requests: Request Response Descriptors: @ [Response Descriptors]]; [Operation Setsmalpblokvoitswetः ^ (RK Objektaraiafestopreshn * operation, Arkemping Reshlt * result) {Anselog (@ "Success!% @", Result); } Failure: ^ (RK Objektaryuefest Operation * Operation, Ansiarar * error) {Anselog (@ "failed with the failure:% @", [error Sthaniykritlekn]); }]; NSOperationQueue * operationQueue = [NSOperationQueue new]; [OperationQuality: Operation];   

JSON snippet

  {"item": [{id}: "abc", "volumeInfo": {"authors": ["123 "]}}   

The resulting data - Please note, & lt; Everything after BLAuthor = 0x08466250. Name = is actually part of NSString property on BLAuthor:

  Success! & Lt; RKMappingResult: 0x8468560, result = {items = ( "& LT; BLVolume = 0x08463F60 | id = mikPQFhIPogC | author = {(& lt; BLAuthor = 0x08466250 | Name = 123 ({HTTP = {request = {URL = \" https: //example.com/?q=123 "; header = {}; method = gate;}; response = {URL = \" https: //example.com/? Q = 123 \ "; header = {\" Cache-control \ "= \" personal, maximum-age = 0, required-modified, no-transform \ "; \" content-type \ "= \" application / jason; charset = UTF-8 \ "; date = \ "Sun, Jun 23 2013 00:41:01 GMT \"; ETag = \ "\\\" I09ELXbrmOlE-RFCkDsRbIJj278 / gPh8_OxpfA9YHXz_P_25F8A4orw \\\ "\"; expired = \ "Sun, Jun 23, 2013 00: 41:01 GMT \ "; All R = Jisi, \ "Transfer-Encoding \" = identity; \ "X-Content-Type-Options \" = Nosniff; \ "X-Frame-Options \" = SAMEORIGIN;   

Anyone who can help me in solving this, thanks in advance! I am at the end of intelligence - tried to remove as many variables as I can from my test, and searched both sources of web and restkit is .

The problem is with mapping

  [authorMapping addPropertyMapping: [ RKAttributeMapping attributeMappingFromKeyPath: zero toKeyPath: @ "name"]];   

You are basically saying: "The code you get on name ".

This can work only when you are suggested 'that the reaction descriptor is being matched to the opposite path of the key. But to do this, you will need to react to the string array standalone back, which is not your case.

According to the same post, you

  [authorMapping addPropertyMapping: [RKAttributeMapping attribute mappingFrompace: @ "" tokaypath: @ "name"]];   

But I suspect it could work.

If you control the API, then I recommend changing the format to make it even more calm after coming back, instead of plain stars inside the array, full resource

No comments:

Post a Comment