iOS 从网络获取json并解析

  • 内容
  • 评论
  • 相关

iOS 从网络获取son并解析

 

NSString* GXURL = PURL;

GXURL = [GXURL stringByAppendingString:@"/index.php/Api/android_getRankByShow/eid/521"],GXURL;

NSURL* url = [NSURL URLWithString:GXURL];

NSString* gongxian = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

 

NSData * data = [gongxian dataUsingEncoding:NSUTF8StringEncoding];//将string 转换成 NSdata

 

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];//将 NSdata转换成 字典

 

//NSLog(@"%@",json);

 

NSString* callBackData = [json valueForKey:@"data"];

//NSLog(@"%@",callBackData);

if([callBackData isEqual:@"0"])

{

 

}

else

{

NSMutableArray *newList = [[NSMutableArray alloc] init];

for(NSArray* item in callBackData)

{

NSString* nickname = [item valueForKey:@"nickname"];

//NSLog(@"%@",nickname);

 

NSString* gongxianStr = [NSString stringWithFormat:@"%@",nickname];

[newList addObject:gongxianStr];

 

 

}

_list = newList;

 

[_devoteTable reloadData];

 

}

评论

0条评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注