我正在使用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);
}];
提前致谢并抱歉我的英文不好,希望你们明白我的问题所在!
----------- EDIT
感谢现在的工作: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"]]];
答案 0 :(得分: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"];