NSString *url1 = @"http://api.kaolafm.com/api/v3.1/radio/playlist?"; NSMutableDictionary *pamsdict = [NSMutableDictionary dictionary]; // radioid=1200000000225; pamsdict[@"radioid"] = rid; AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; //申明返回的结果是json类型 manager.responseSerializer = [AFJSONResponseSerializer serializer]; //申明返回的结果是json类型 manager.responseSerializer = [AFJSONResponseSerializer serializer]; [manager GET:url1 parameters:pamsdict success:^(AFHTTPRequestOperation *operation, id responseObject) { // NSLog(@"%@\n 成功",responseObject); NSLog(@"%@",[NSThread currentThread]); // NSDictionary *dict = responseObject; // NSDictionary *dict2 = dict[@"result"]; // NSArray *objarr = dict2[@"dataList"]; //KVC牛逼之处,上面是笨方法 NSArray *objarr = [responseObject valueForKeyPath:@"result.dataList"]; // NSLog(@"%@",objarr[0]); [self.ProfileArr removeAllObjects]; for ( NSDictionary *channeldict in objarr) { ProfileMusic *pMusuic = [ProfileMusic ProfileWithDict:channeldict ]; [self.ProfileArr addObject:pMusuic]; } _sortedArr = [self.ProfileArr sortedArrayWithOptions:NSSortConcurrent usingComparator:^NSComparisonResult(id obj1, id obj2) { ProfileMusic *Proobj1 = obj1; ProfileMusic *Proobj2 = obj2; int nu1 = [Proobj1.orderNum intValue]; int nu2 = [Proobj2.orderNum intValue]; if (nu1 > nu2) { return NSOrderedAscending; }else if (nu1 == nu2){ return NSOrderedSame; }else{ return NSOrderedDescending; } }]; [self.tableView reloadData]; [self.urc endRefreshing]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { NSLog(@"%@\n失败",error); }];
时间: 2024-09-24 01:27:05