zoukankan      html  css  js  c++  java
  • iOS学习笔记25-Json数据解析

    JSON数据实例

    首先找到路径

     NSString *strUrl = @"http://localhost/Stu.json";

    得到request

     NSURL *url = [NSURL URLWithString:strUrl];

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        NSURLResponse *response = nil;

        NSError *error = nil;

    得到data

        NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

    //定义解析 Json 的对象

        NSMutableArray *arr =  [NSJSONSerialization JSONObjectWithData:data

                                        options:kNilOptions

                                          error:&error];

        NSLog(@"%@",arr);

        //字典转模型

        NSMutableArray *arrM = [NSMutableArray arrayWithCapacity:arr.count];

        for(NSDictionary *dic in arr){

            NSLog(@"%@",dic);

            Stu *stu = [[Stu alloc]initWithDictionary:dic];

            NSLog(@"stu = %@",stu);

            [arrM addObject:stu];

        }

        for (int i =0; i<arrM.count; i++) {

            NSLog(@"stu = %@",arrM[i]);

        }

    运行结果

     

  • 相关阅读:
    计算机网络
    RedHat 7本地yum源的配置
    linux 查看电脑信息
    liunx下的网络配置
    缺陷是什么
    linux下的yum的安装和配置
    软件测试术语总结
    Loadrunner相关流程
    防火墙的相关概念
    软件测试W模型
  • 原文地址:https://www.cnblogs.com/adodo/p/5220290.html
Copyright © 2011-2022 走看看