AFNetworking and jSON

2019-02-01 23:12发布

I am getting following the json response from a web-service api. I want to extract product data from the json. I also want to implement this using AFNetworking.

 {"products": [
    {
      "product_id": "1170",
      "name": "zzzz®",
      "sort_order": 0,
      "brand": "zzzas",
      "product_category_id": "1090",
      "location_ids": [
        "1078"
      ],
      "icon_url": "http://zzzzz.com/media/2502/zzzz.png",
      "icon_date": "Wed, 07 Nov 2012 14:03:47 GMT",
      "thumbnail_url": "http://zzzz.com/media/2591/zzdfs.png",
      "thumbnail_date": "Wed, 07 Nov 2012 14:04:02 GMT"
    },
    {
      "product_id": "1126",
      "name": "ddddd®",
      "sort_order": 1,
      "brand": "dddsas",
      "product_category_id": "1110",
      "location_ids": [
        "1095"
      ],
      "icon_url": "http://zzzzz.com/media/2507/ddddd.png",
      "icon_date": "Wed, 07 Nov 2012 14:03:48 GMT",
      "thumbnail_url": "http://zzzzz.com/media/2596/sssds.png",
      "thumbnail_date": "Wed, 07 Nov 2012 14:04:05 GMT"
    }
]}

Can anyone suggest a way to do this.me how the things will be done.

7条回答
Explosion°爆炸
2楼-- · 2019-02-01 23:44

if you're using AFNetworking 3.0, AFJSONRequestOperation doesn't exist anymore, you have to use AFHTTPSessionManager :

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@"http://example.com/resources.json" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];
查看更多
登录 后发表回答