在我向服务器请求之后,我收到了两种不同类型的响应
如果成功响应就是这个
[{"id":5,"is_default":0,"name":"Dutch","language_id":3},{"id":4,"is_default":1,"name":"French","language_id":2}]
其他响应类型是
{"status":102,"response":"Empty record list."}
是否有任何方法可以检测“状态”键是否可用以响应 objc. 谢谢
找到解决方案
//break it from result tag
if([[responseString JSONValue] isKindOfClass:[NSDictionary class]]){
NSDictionary *dict = [responseString JSONFragmentValue];
if([dict count]==2){
return;
}
//nothing to load
}
最佳答案
响应只是一个字典,所以要查看您是否有您正在寻找的键,您可以使用 NSDictionary 方法:
// 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"];
关于iphone - 如何检查 ios 中的 json 响应中的 key 是否可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16624431/