I am currently trying to convert the JSON Representation of some Objects into an NSArray. I used RestKit to get the Response through our API and now I want to convert the RKResponse into an Array of Objects. How can I do this ?
2 Answers
NSData* data = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSArray *values = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; // if you are expecting the JSON string to be in form of array else use NSDictionary instead
The above code works good for iOS 5 and above
7 Comments
Sebastian Boldt
Ok maybe i should describe my problem a little bit more detailed. I got an Array of Json Objects in form of a RKRESPONSE and now i want to convert it into an Array with real Objective -C Objects with propertys and so one ...
AppleDelegate
What is the dataType of RKRESPONSE.Is it NSDATA or some other??
Sebastian Boldt
RKRESPONSE is defined inside the RestKit Headers. It has its own Type.
Sebastian Boldt
I can convert it to a string like the following : NSData *tempWishes = [[response bodyAsString]dataUsingEncoding:NSUTF8StringEncoding];
Jonathan F.
Works fine, and pretty simple.
|