一: json 

  1. 什么是json

    1.1 json是一种轻量级的数据格式,一般用于数据交互。

    1.2 服务器返回给客户端的数据,一般都是JSON或者XML格式(文件下载除外)。

 

  2. JSON的格式很像OC中的字典和数组

  

    2.1 需要注意json中的key必须用双引号!

  

  3. 想要从json中挖掘数据,必须对json进行解析。

    3.1 json --- oc转换对照表

   

    

     

 

 

 二: json解析方案

    1.json - oc 对象

    + (nullable id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error;  

    注意是返回的是id类型的

 

     2.代码:

    NSURL *url = [NSURL URLWithString:@"http://120.25.226.186:32812/login?usename=520it&pwd=520it"];
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
        // 解析json
        NSDictionary *dic =    [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
        NSLog(@"%@",dic[@"error"]);
    }];