我想從json傳遞一些值給UIAlertView的消息。我有一些代碼如何從JSON調用NSString到UIAlertView?
- (void)jsonParse{
NSString* path = @"http://phdprototype.tk/getResultData.php";
NSURL* url = [NSURL URLWithString:path];
NSString* jsonString = [[NSString alloc]initWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
NSData* jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableLeaves error:nil];
NSDictionary* resultDic = [dic objectForKey:@"maxid"];
NSString* recData = [resultDic objectForKey:@"recommendData"];
NSString* rData = [resultDic objectForKey:@"room"];
NSString* lData = [resultDic objectForKey:@"level"];
}
- (void)locationView
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"Recommendation"
message:[NSString stringWithFormat:@"OK! There is another collection which located at room %@ in level %@."]
delegate: self
cancelButtonTitle: nil
otherButtonTitles: @"GO", nil];
[alert show];
}
據我所知,我必須做一些
message:[NSString stringWithFormat:@"OK! There is another collection which located at room %@ in level %@."]
。但是,我不知道該怎麼做。有人能告訴我如何將lData和rData的值傳遞給uialertview的消息嗎?
你應該學習Objective-C第一次啓動編碼之前。這會幫助你。 – Amar