0

我正在使用 AFNetworking 解析一些 json 并且非常喜欢它。

现在我想更深入地利用杠杆。我的 json 输出看起来像这样

-result
  -0
    rezept_id : value1
    rezept_name : value2
    rezept_zubereitung : value3

直到这里一切正常,我可以解析该值。但现在它继续这样

-rezept_bilder
  -0    
    -bigfix

      file : value4
      file_path : value5

现在我想解析 json 属性文件值(value4)并将其显示在图像视图中。为了显示图像,如果它在主屏幕上,我会做这样的事情。

[self.restuarantImageView setImageWithURL:[NSURL URLWithString:[self.restuarantDetail objectForKey:@"file"]]];

但是我怎么告诉他文件值不在主目录下,而是在下面

-rezept_bilder
 -0
  - bigfix

这是我用来将数据解析到我卡住的那一点的代码。

-(void)makeRestuarantsRequests3{


    NSURL *url = [NSURL URLWithString:@"http://api.chefkoch.de/api/1.0/api-recipe.php?    zufall=1&divisor=0&limit=1"];

   NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
                                                                                    success:^(NSURLRequest *request, NSHTTPURLResponse *response, id responseObject) {
                                                                                        self.googlePlacesArrayFromAFNetworking3 = [responseObject objectForKey:@"result"];
                                                                                        NSDictionary *tempDictionary3= [self.googlePlacesArrayFromAFNetworking3 objectAtIndex:0];
                                                                                      self.zubereitung.text = [tempDictionary3 objectForKey:@"rezept_zubereitung"];
                                                                                             self.Name.text = [tempDictionary3 objectForKey:@"rezept_name"];


                                                                                    }
                                                                                    failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id responseObject) {
                                                                                        NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo);


                                                                                    }];

在此先感谢并为我的英语不好感到抱歉,希望你们能理解我的问题所在!

- - - - - -编辑

谢谢它现在可以工作了:D

你真的治愈了我

我就是这样做的

-(void)makeRestuarantsRequests3{


NSURL *url = [NSURL URLWithString:@"http://api.chefkoch.de/api/1.0/api-recipe.php?zufall=1&divisor=0&limit=1"];

   NSURLRequest *request = [NSURLRequest requestWithURL:url];

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
                                                                                    success:^(NSURLRequest *request, NSHTTPURLResponse *response, id responseObject) {
                                                                                        self.googlePlacesArrayFromAFNetworking3 = [responseObject objectForKey:@"result"];
                                                                                        NSDictionary *tempDictionary3= [self.googlePlacesArrayFromAFNetworking3 objectAtIndex:0];
                                                                                      self.zubereitung.text = [tempDictionary3 objectForKey:@"rezept_zubereitung"];
                                                                                             self.Name.text = [tempDictionary3 objectForKey:@"rezept_name"];


                                                                                        self.googlePlacesArrayFromAFNetworking5 =[tempDictionary3 objectForKey:@"rezept_bilder"];

                                                                                        NSDictionary *tempDictionary4= [self.googlePlacesArrayFromAFNetworking5 objectAtIndex:0];

                                                                                        NSDictionary *tempDictionary5 = [tempDictionary4 objectForKey:@"bigfix"];


                                                                                        [self.Bild setImageWithURL:[NSURL URLWithString:[tempDictionary5 objectForKey:@"file"]]];
4

1 回答 1

0

尝试像下面那样更改它并查看。如果可能的话把responseObject的JSON贴出来,看的更清楚。

self.googlePlacesArrayFromAFNetworking3 = [responseObject objectForKey:@"result"];                                                         

NSDictionary *tempDictionary3= [[self.googlePlacesArrayFromAFNetworking3 objectAtIndex:0] obejctForKey:@"bigfix"];

self.zubereitung.text = [tempDictionary3 objectForKey:@"rezept_zubereitung"];                                                                                             
self.Name.text = [tempDictionary3 objectForKey:@"rezept_name"];
于 2013-07-24T08:09:39.387 回答