7

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 ?

1
  • Is there any delimeter to distinguish between your object string? Post an example response. Commented Oct 30, 2012 at 12:59

2 Answers 2

25
 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

Sign up to request clarification or add additional context in comments.

7 Comments

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 ...
What is the dataType of RKRESPONSE.Is it NSDATA or some other??
RKRESPONSE is defined inside the RestKit Headers. It has its own Type.
I can convert it to a string like the following : NSData *tempWishes = [[response bodyAsString]dataUsingEncoding:NSUTF8StringEncoding];
Works fine, and pretty simple.
|
2

Try importing RestKit/RKJSONParserJSONKit.h. Then use try the method objectFromString:error:. To get a NSDictionary representation. From the NSDictionary you can get the array.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.