Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 基于ASP.net Web服务的AFN网络_Objective C_Json_Afnetworking - Fatal编程技术网

Objective c 基于ASP.net Web服务的AFN网络

Objective c 基于ASP.net Web服务的AFN网络,objective-c,json,afnetworking,Objective C,Json,Afnetworking,我使用getPath方法调用我的Web服务,如下所示: [[AFTwitterAPIClient sharedClient] getPath:@"GetWineCategoryList" parameters:parameters success:^(AFHTTPRequestOperation *operation, id JSON) { NSLog(@"JS

我使用getPath方法调用我的Web服务,如下所示:

[[AFTwitterAPIClient sharedClient] getPath:@"GetWineCategoryList"
                                parameters:parameters success:^(AFHTTPRequestOperation *operation, id JSON) {
                                    NSLog(@"JSON = %@",JSON);
                                    NSMutableArray *mutableTweets = [NSMutableArray arrayWithCapacity:[JSON count]];
                                    for (NSDictionary *attributes in mutableTweets) {
                                        Tweet *tweet = [[Tweet alloc] initWithAttributes:attributes];
                                        [mutableTweets addObject:tweet];
                                    }

                                    if (block) {
                                        block([NSArray arrayWithArray:mutableTweets], nil);
                                    }
                                } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                    if (block) {
                                        block([NSArray array], error);
                                    }
                                }];
它总是作为NSData输出。如果我将这个NSData转换成一个字符串,就会得到一个JSON字符串

JSON = <5b7b2243 61746567 6f72794e 616d6522 3a224f54 48455222 7d2c7b22 43617465 676f7279 4e616d65 223a2252 4544227d 2c7b2243 61746567 6f72794e 616d6522 3a22524f 5345227d 2c7b2243 61746567 6f72794e 616d6522 3a225748 49544522 7d5d>
JSON=
为什么不转换为NSArray?

您可以使用将NSData对象转换为NSArray

NSArray *array = (NSArray*)[NSJSONSerialization JSONObjectWithData:JSON 
                                                 options:0
                                                   error:&error];

这假设您知道您的JSON是数组类型而不是字典类型。

是的,它可以工作,但不应该自动为我这样做。我在Twitter的API上使用了相同的方法,它工作得很好。Fnetworking不知道响应的格式,这就是为什么将响应作为原始数据(NSData)提供的原因。这取决于您如何正确地转换它。要让它自动工作,您不需要在AFNetwork中使用JSON特定的子类吗?