iOS实现从服务器请求json数据并转化成NSDictionary

NSURL *url = [NSURL URLWithString:URL];

NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadRevaildatingCacheData timeoutInterval:10];

NSURLResponse *response;

NSError *error;

NSData *data = [NSURLConnection sendSynchronousRequest returningResponse:&response error:&errro];

 

NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

 

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];

NSLog(@"%@\n %@",str,dic);

posted @ 2015-03-27 10:56  天使的翅膀——  阅读(1488)  评论(0编辑  收藏  举报