美文网首页
json解析3

json解析3

作者: nothing_c | 来源:发表于2016-10-27 00:49 被阅读7次

    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

          本文链接:https://www.haomeiwen.com/subject/tkujuttx.html