【发布时间】:2015-11-10 19:33:59
【问题描述】:
在我的 Parse 云代码中,我有这样的自定义错误
response.error({
"Error" : "DEAL EXPIRED",
"Title" : "Sorry!",
"Message" : "This deal is expired :(",
"Action" : "Ok"
});
因为我想显示一个 UIAlertView,但是我在阅读字典时遇到了问题。我在应用程序中的代码是:
NSDictionary *errorDictionary = [error userInfo];
if ([[errorDictionary objectForKey:@"Error"] isEqualToString:@"DEAL EXPIRED"]) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:
[NSString stringWithFormat:@"%@",[errorDictionary objectForKey:@"Title"]]
message:[NSString stringWithFormat:@"%@",[errorDictionary objectForKey:@"Message"]]
delegate:nil
cancelButtonTitle:[NSString stringWithFormat:@"%@",[errorDictionary objectForKey:@"Action"]]
otherButtonTitles:nil];
[alert show];
}
errorDictionary的日志是:
{"Error":"DEAL EXPIRED","Title":"Sorry!","Message":"This deal is expired :(","Action":"Ok"}
谢谢
【问题讨论】:
-
你有什么问题?
-
代码不进入if语句。也许必须解析字典
-
如果在
if语句之前执行NSLog(@"the error is: %@",[errorDictionary objectForKey:@"Error"]);会发生什么? -
您打印的日志肯定看起来像 JSON 字符串,而不是
NSDictionary实例... -
@Wain 是的,很可能
标签: ios objective-c parse-platform nserror