-2

The response is something like this

Array({"ResultSet":{"Query":"xxxx","Result":[]}})

How to parse the string into a NSArray?

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70
Keoros
  • 1,337
  • 2
  • 13
  • 23

1 Answers1

2

it should work with NSJSONSerialization, it converts NSData input to all foundation objects (NSArray, NSDictionary):

NSError *error;
NSArray *data = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
if (error) {
    //handle error
} else {
    NSLog(@"%@", data);
}
Hannes
  • 3,752
  • 2
  • 37
  • 47
  • It seems it doesn't work with array data. I got the following error[ error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 3840.)" (JSON text did not start with array or object and option to allow fragments not set.) UserInfo=0x10f73c2b0 {NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}] – Keoros Dec 20 '13 at 05:08
  • your response might be malformed. did you verify it with a json validation service (e.g. http://jsonlint.com/)? – Hannes Dec 20 '13 at 07:09