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]);

        }

    运行结果

     

  • 相关阅读:
    python中的operator.itemgetter函数
    win10下安装Cygwin配置gcc编译环境
    英文单词拼写纠错
    关于文本处理之结巴分词
    mysql 主从复制
    YII2.0 增删改查
    Linux screen命令简介
    Zookeeper简介与安装
    如何在Linux上安装Tomcat
    Java学习笔记之自定义异常
  • 原文地址:https://www.cnblogs.com/adodo/p/5220290.html
Copyright © 2011-2022 走看看