【问题标题】:AFNetworking parsing json deeperAFNetworking 解析 json 更深
【发布时间】:2013-07-24 07:57:01
【问题描述】:

我正在使用 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"]]];

【问题讨论】:

    标签: ios json afnetworking


    【解决方案1】:

    尝试像下面那样更改它并查看。可以的话把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"];
    

    【讨论】:

    • 感谢您的快速回复。还没有测试它,但我认为你的代码中缺少“rezept_bilder”对象?
    • 是的,将第 1 行中的“结果”更改为“rezept_bilder”。希望您知道如何操作!
    猜你喜欢
    • 1970-01-01
    • 2013-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-24
    • 1970-01-01
    相关资源
    最近更新 更多