2014-02-23 121 views
0

我正在提出一个有时会返回错误消息示例错误的请求:“没有现场游戏”。检查valueForKey是否存在

如何检查valueforkey:error是否存在?

if (error exists) { 
//nothing 
} else { 
//return other value for keys 
} 

我的要求

NSDictionary* headers3 = @{@"X-Mashape-Authorization": @"key"}; 
NSDictionary* parameters3 = @{}; 

UNIHTTPJsonResponse* response3 = [[UNIRest get:^(UNISimpleRequest* request3) { 
    [request3 setUrl:@"https://willjw-statsfc-competitions.p.mashape.com/live.json?key=uNzRmnUdCEYKdOoe1e1bBpwtmczNVLUZYbIlOX9O&competition=europa-league&timezone=Europe%2FLondon"]; 

    [request3 setHeaders:headers3]; 
    [request3 setParameters:parameters3]; 
}] asJson]; 


NSData* rawBody3 = [response3 rawBody]; 
results3 = [NSJSONSerialization JSONObjectWithData:rawBody3 options:NSJSONReadingMutableContainers error:nil]; 
+1

显示成功和错误条件的样本JSON .. – Wain

回答

0

好像而不是 “错误” 你的API返回 “消息”。总之,这里就是你要做的:

if (result3[@"message"]) { // equavalent of [result3 objectForKey:@"message"], which will return nil if there's no "message" key in the dictionary 
    // your error handler condition 
} 
else { 
    // process retrieved data 
} 
+0

返回: 错误=“没有找到比赛实况”; – user3258468

+0

猜你可以使用'result3 [@“error”]'then – Eugene