ios - Trouble With RKMappingResult. Can't find a way to get NSDictionary from result -
i trying incorporate restkit v.20 ios app. proper mapping result rkobjectrequestoperation can't figure out way put nsdictionary. returned array of objects of hex values. can values of specific items want using objectatindex: need place has values in string format, not hex. can change hex string setting associated class equal single array object. want general list can predicate use in search.
here json data:
{ "carsinshop": [ { "car": { "id": "1", "name": "mercedes", "year": "2000" } }, { "car": { "id": "2", "name": "bmw", "year": "2004" } }, { "car": { "id": "3", "name": "audi", "year": "2001" } }, { "car": { "id": "4", "name": "lexus", "year": "2011" } }, { "car": { "id": "5", "name": "toyota", "year": "2006" } }, ], "count": 5 }
here having code problems:
nsurl *url = [nsurl urlwithstring: @"http://localhost:8888/testphpread/index.php"]; nsurlrequest *request = [nsurlrequest requestwithurl:url]; rkobjectrequestoperation *objectrequestoperation = [[rkobjectrequestoperation alloc] initwithrequest:request responsedescriptors:@[responsedescriptor]]; [objectrequestoperation setcompletionblockwithsuccess:^(rkobjectrequestoperation *operation, rkmappingresult *mappingresult) { rkloginfo(@"carsinshoparray: %@", mappingresult.array); carsinshoparray = [mappingresult array]; carsinshop* carsinshop = [carsinshoparray objectatindex:0]; nslog(@"loaded car id #%@ -> name: %@, year: %@", carsinshop.car.id, carsinshop.car.name, carsinshop.car.year); } failure:^(rkobjectrequestoperation *operation, nserror *error) { rklogerror(@"operation failed error: %@", error); }];
this nslog:
carsinshoparray: ( "carsinshop: 0xa26b0f0", "carsinshop: 0xa46b2f0", "carsinshop: 0xa46af20", "carsinshop: 0xa46b7a0", "carsinshop: 0xa46bd90", ) loaded car id #1 -> name: mercedes, year: 2000
so see can individual items, need access dictionary whole, use in searching.
you have custom class carsinshop
, guess inherits nsobject
. don't override description
method default description when log instance. default class name , pointer. that's why "carsinshop: 0xa26b0f0"
. says nothing contents of instance.
when say: "i need access dictionary whole"
, don't have dictionary. have array of custom objects. can still use kvc search through items in array (based on key path of log statement).
you can array of cars doing:
nsarray *cars = [carsinshoparray valueforkey:@"car"];
Comments
Post a Comment