美文网首页
解析数据

解析数据

作者: 阿窝额咦呜芋 | 来源:发表于2018-05-23 14:01 被阅读0次

    Model.h

    #import <Foundation/Foundation.h>
    typedef void(^HouBlock)(NSDictionary *relust);
    @interface Hou : NSObject
    //解析方法
    +(void) httpGet:(NSString *)UrlString Cyy:(NSDictionary *) paramneters relust:(HouBlock)relust;
    @end

    Model.m

    #import "Hou.h"

    #import "AFNetworking.h"

    @implementation Hou

    +(void)httpGet:(NSString *)UrlString Cyy:(NSDictionary *)paramneters relust:(HouBlock)relust

    {

        AFHTTPSessionManager *Manger=[AFHTTPSessionManager manager];

        Manger.responseSerializer = [AFHTTPResponseSerializer serializer];

        [Manger GET:UrlString parameters:paramneters progress:^(NSProgress * _Nonnull downloadProgress) {

        } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {

            id obj = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:NULL];

    //        NSDictionary *dict = obj[@"weatherinfo"];

            relust(obj);

        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        }];

    }

    @end

    获取网络数据

    //获取网址数据

        NSString *url=@"http://app.cad.com.cn/cad.php?method=channel&cid=88&page=1&limit=10";

        [Hou httpGet:url Cyy:nil relust:^(NSDictionary *relust) {

            NSArray *arr=relust[@"data"];

            _arraya = [[NSMutableArray alloc] init];

    //        NSLog(@"%@",arr);

            for (int i=0; i

    相关文章

      网友评论

          本文标题:解析数据

          本文链接:https://www.haomeiwen.com/subject/qssrjftx.html