1,不浪费时间,本代码经实践检验通过!
//网络请求代码段
//post request
NSURL *url=[NSURL URLWithString:@"http://192.168.253.101:8080/ERP/mobile/login.action"];
NSMutableURLRequest *request =[[NSMutableURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10];
//设置请求方式
[request setHTTPMethod:@"POST"];
//设置参数
NSString *str=@"username=A023&password=1&master=UAS";
NSData *data=[str dataUsingEncoding:NSUTF8StringEncoding];
[request setHTTPBody:data];
//连接服务器
NSData *received=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *strl=[[NSString alloc]initWithData:received encoding:NSUTF8StringEncoding];
// NSLog(@"结果:%@",strl); ---自定义json 格式字符串 包含集合和数组形式 采用原生类库解析的方式
NSError *error;
NSString *temstr=@"{\"count\":50,\"allprocess\":[{\"name\":\"神圣天使\"},{\"name\":\"商品天使\"},{\"name\":\"美丽天使\"}]}";
NSLog(@"temstr=%@",temstr);
NSData *rdata=[temstr dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"rdata=%@",rdata);
NSDictionary *json=[temstr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
NSLog(@"json=%@",json);
NSArray *elist=[json objectForKey:@"allprocess"];
NSString *uu=[elist objectAtIndex:1];
NSString *u_name=[[elist objectAtIndex:1] objectForKey:@"name"];
NSLog(@"elist=%@",elist);
NSLog(@"elist=%@",uu);
NSLog(@"elist=%@",u_name);
for (int i=0;i<[elist count];i++) {
NSLog(@"遍历数组 \n %i=%@",i,[[elist objectAtIndex:i] objectForKey:@"name"]);
}