解析数据

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容