gpt4 book ai didi

ios - AFNetworking 和 jSON

转载 作者:IT王子 更新时间:2023-10-29 08:16:52 25 4
gpt4 key购买 nike

我正在关注来自网络服务 API 的 json 响应。我想从 json 中提取产品数据。我也想使用 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"
}
]}

任何人都可以建议一种方法来做到这一点我将如何完成这些事情。

最佳答案

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"link"]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
NSDictionary *jsonDict = (NSDictionary *) JSON;
NSArray *products = [jsonDict objectForKey:@"products"];
[products enumerateObjectsUsingBlock:^(id obj,NSUInteger idx, BOOL *stop){
NSString *productIconUrl = [obj objectForKey:@"icon_url"];
}];

} failure:^(NSURLRequest *request, NSHTTPURLResponse *response,
NSError *error, id JSON) {
NSLog(@"Request Failure Because %@",[error userInfo]);
}
];

[operation start];

试试这个。

更新 1:您可以试试这个 https://github.com/SSamanta/SSRestClient

更新 2:https://github.com/SSamanta/SSHTTPClient (使用 swift )

可用 Pod : pod 'SSHTTPClient', '~>1.2.2'

关于ios - AFNetworking 和 jSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13473811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com