Reputation: 1275
After i request to the server , i recieve two different type of response
if it is success response will be this
[{"id":5,"is_default":0,"name":"Dutch","language_id":3},{"id":4,"is_default":1,"name":"French","language_id":2}]
other response type would be
{"status":102,"response":"Empty record list."}
Is the any way to detect whether the "status" key is available or not in response in objc. Thanks
found a solution
//break it from result tag
if([[responseString JSONValue] isKindOfClass:[NSDictionary class]]){
NSDictionary *dict = [responseString JSONFragmentValue];
if([dict count]==2){
return;
}
//nothing to load
}
Upvotes: 0
Views: 1829
Reputation: 17186
Parse
the JSON
response into object
. Check if parsed object
is dictionary
, then check the key "status"
.
If the parsed object
is an array
, then access the results
from index
.
Upvotes: 2
Reputation: 150615
The response is just a dictionary, so to see if you have the key you are looking for you can just use the NSDictionary methods:
// Assume you have already created a dictionary, jsonResponse, from your JSON
// First, get all the keys in the response
NSArray *responseKeys = [jsonResponse allKeys];
// Now see if the array contains the key you are looking for
BOOL isErrorResponse = [responseKeys containsObject:@"status"];
Upvotes: 2