zoukankan      html  css  js  c++  java
  • IOS开发--第二阶段--通讯--JSON系统解析

    JSON系统解析:

    1,创建请求路径和URL;

    2,根据URL构建请求 ,如果是POST 使用NSMutableURLRequest , NS可变的URL请求;

    NSMutableURLRequest *mutableURLRequest = [NSMutableURLRequest requestWithURL:url];

    3,构建连接 1、同步 2、异步;

    NSData *responseData = [NSURLConnection sendSynchronousRequest:mutableURLRequest returningResponse:nil error:nil];

    4,将data转化为字符串 查看数据的正确性;

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        NSLog(@"responseString___%@", responseString);

    5,使用系统类解析 1、要解析的数据 2、选项设置 3、错误信息;

        NSError *error = nil;

        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:responseData  options:NSJSONReadingMutableContainers error:&error];

        NSLog(@"dictionary____%@", dictionary);

        NSLog(@"%d_______%@", error.code, error.localizedDescription);

  • 相关阅读:
    Appium
    Appium滑动直到页面底部
    使用Maven以及碰到的坑们(持续更新中。。。)
    通过license server激活IntelliJ IDEA
    HDU 1166
    HDU 2444
    HDU 浙江科技学院校赛2016
    HDU 5651
    HDU 5650
    Interview 位运算
  • 原文地址:https://www.cnblogs.com/gegeboke/p/4368493.html
Copyright © 2011-2022 走看看