mkral
mkral

Reputation: 4085

JSON iOS failed Error

So I have a web service that returns this JSON:

[{"other_user":"54","distance":"1 ft","duration":"1 min"},{"other_user":"55","distance":"2 ft","duration":"5 min"}]

Then in my ios app I use:

NSString *responseString = [request responseString];
    NSArray *responseArray = [responseString JSONValue];
    for (NSDictionary* item in responseArray) {
        NSString *otherUser = [item objectForKey:@"other_user"];
        NSString *otherDistance = [item objectForKey:@"distance"];
        NSString *otherDuration = [item objectForKey:@"duration"];

       NSLog(@"user: %@  distance: %@  time: %@", otherUser, otherDistance, otherDuration);
    }

but I am getting this error:

-JSONValue failed. Error is: Illegal start of token [S]

Any help is appreciated, I have no Idea where to look/debug

Upvotes: 0

Views: 186

Answers (1)

timthetoolman
timthetoolman

Reputation: 4623

try the following:

SBJSON *parser = [[SBJSON alloc] init];
NSString *responseString = [request responseString];

NSError *jsonError=nil;
NSArray *responseArray = [parser objectWithString: responseString error: &jsonError];

if (jsonError==nil) {
   for (NSDictionary* item in responseArray) {
      NSString *otherUser = [item objectForKey:@"other_user"];
      NSString *otherDistance = [item objectForKey:@"distance"];
      NSString *otherDuration = [item objectForKey:@"duration"];

      NSLog(@"user: %@  distance: %@  time: %@", otherUser, otherDistance, otherDuration);
   }
}

Good Luck

t

Upvotes: 1

Related Questions