json解析3

SBJson


//需要在头文件处导入SBJson文件夹中的SBJson.h

//请求数据

NSURL* url = [NSURLURLWithString:@"http://localhost:8080/Login1/NewServlet?command=5"];

NSURLRequest* request = [NSURLRequestrequestWithURL:url];

[NSURLConnectionsendAsynchronousRequest:requestqueue:[[NSOperationQueuealloc]init]completionHandler:^(NSURLResponse*_Nullableresponse,NSData*_Nullabledata,NSError*_NullableconnectionError) {

NSString* str = [[NSStringalloc]initWithData:dataencoding:NSUTF8StringEncoding];

//初始化SBJson

SBJSON* json = [[SBJSONalloc]init];

//接收SBJson中的字典数据

NSDictionary* dic = [jsonobjectWithString:strerror:nil];

NSLog(@"-----%@",dic);

//初始化接收对象的数组

_userArr= [[NSMutableArrayalloc]init];

//接收字典中名为"Parma"的数组

NSArray*arr = [dicobjectForKey:@"parma"];

//遍历数组中的字典数据

for(NSDictionary* dicinarr) {

//初始化对象

User* user = [[Useralloc]init];

//解析接收值

user.name= [dicobjectForKey:@"name"];

user.pwd= [dicobjectForKey:@"pwd"];

user.age= [dicobjectForKey:@"age"];

user.trueName= [dicobjectForKey:@"tureName"];

//在接收对象的数组中添加对象

[_userArraddObject:user];

NSLog(@"----====%@",_userArr);

}

}];

你可能感兴趣的:(json解析3)