Asad Khan
Asad Khan

Reputation: 11899

How can I check if the response is a valid JSON in cocoa

Is there a way to check if the response from a web service call is valid JSON?

I am using ASIHTTP by the way for all communication.

Upvotes: 1

Views: 1024

Answers (1)

user94896
user94896

Reputation:

Attempt to parse the response—if you are successful, it's valid JSON. For example, if you were using json-framework:

SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease];
id object = [parser objectWithString:[request responseString]];

if (object != nil) {
  // Success!
}

Upvotes: 4

Related Questions