JSONKit网络解析

引入#import "JSONKit.h"

下面主要差别在于中间转化的死NSString还是NSData类型

1、

    NSURL *url =[NSURL URLWithString:@"http://www.weather.com.cn/data/cityinfo/101010100.html"];
   

    NSString *jsonStr =[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
   

    NSData *jsondata = [jsonStr dataUsingEncoding:NSUTF8StringEncoding];
   

    NSDictionary *dic =[jsondata objectFromJSONData];
   

    NSDictionary *dic1 =[dic objectForKey:@"weatherinfo"];
   

    NSLog(@"%@", [dic1 objectForKey:@"city"]);

2、创建JSONDecoder类进行解析

    NSURL *url =[NSURL URLWithString:@"http://www.weather.com.cn/data/cityinfo/101010100.html"];
  

    NSData *jsonData = [NSData dataWithContentsOfURL:url];
 

    JSONDecoder *decoder =[JSONDecoder new];
 

    id jsondata = [decoder objectWithData:jsonData];

   

    NSDictionary *dic =(NSDictionary*)jsondata;
 

    NSDictionary *dic1 =[dic objectForKey:@"weatherinfo"];
 

    NSLog(@"%@", [dic1 objectForKey:@"city"]);

3、

    NSURL *url =[NSURL URLWithString:@"http://www.weather.com.cn/data/cityinfo/101010100.html"];
   

    NSString *jsonStr =[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
  

    NSDictionary *dic = [jsonStr objectFromJSONStringWithParseOptions:JKParseOptionLooseUnicode];
 

    NSDictionary *dic1 =[dic objectForKey:@"weatherinfo"];
 

    NSLog(@"%@", [dic1 objectForKey:@"city"]);


我们现在使用的JSONKit有许多问题我们需要进行修改之后才可以使用

1、TARGETS->Build Phases->Compile Sources中找到JSONKit.m文件在后面双击添加  -fno-objc-arc

2、JSONKit中运用了很多isa,因此有两种修改方式,改成其中一种即可,建议第二种

   (1)Build Setting中搜索框中输入isa进行搜索,下面会显示Direct usage of 'isa' 将后边改成NO

   (2)在JSONKit.m文件中进行修改:     

          1> 修改JSONKit.m文件第680行,修改为object_setClass(array, _JKArrayClass);
          2> 修改JSONKit.m文件第931行,修改为object_setClass(dictionary, _JKDictionaryClass);



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值