我是编码新手,想知道是否有人可以帮助我。我是第一次使用网络服务。我在访问任何数组时都遇到了麻烦。我什么都弄不出来。
现在我可以成功地从 Web 服务获取信息并将其存储在 NSArray 中。我 NSLog 它并看到内容出现在我的控制台中。我检查了数组的计数,它是 5。
但我无法访问任何内容。错误状态:CustomTableView[4083:11303] -[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0xff231b0
我真的很想知道如何访问数组中的各种值。在此先感谢您的帮助!:)
@property (strong, nonatomic) NSArray *searchedYummlyRecipeList;
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
self.searchedYummlyRecipeList = [NSJSONSerialization JSONObjectWithData:self.yummlyRecipesData options:nil error:nil];
//test logging
NSLog(@"Recipe List: %@ ", self.searchedYummlyRecipeList);//prints fine
NSLog(@"Count of test array: %lu", (unsigned long)[self.searchedYummlyRecipeList count]);//prints fine
NSArray *testArray = [[self.searchedYummlyRecipeList objectAtIndex:1]objectForKey:@"criteria"];//breakpoint is here
NSLog(@"test Array: %@", testArray);//doesn't get here
NSLog(@"test Array count: %lu", (unsigned long)[testArray count]);//doesn't get here
}
nslog 输出的提取:
Recipe List: {
attribution = {
html = "<a href='http://www.yummly.com/recipes/onion-soup'>onion soup recipes</a> search powered by <img src='http://static.yummly.com/api-logo.png'/>";
logo = "http://static.yummly.com/api-logo.png";
text = "onion soup recipes: search powered by Yummly";
url = "http://www.yummly.com/recipes/onion-soup";
};
criteria = {
allowedIngredients = (
);
excludedIngredients = (
);
facetFields = (
);
maxResults = 6;
requirePictures = 0;
resultsToSkip = 0;
terms = (
onion,
soup
);
};
facetCounts = {
};
matches = (
{
attributes = {
course = (
Soups,
Appetizers
);
cuisine = (
French
);
holiday = (
Thanksgiving
);
};
flavors = {
bitter = "0.1666666666666667";
meaty = "0.1666666666666667";
piquant = 0;
salty = "0.1666666666666667";
sour = "0.1666666666666667";
sweet = "0.1666666666666667";
};
id = "French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364";
ingredients = (
"beef broth",
"minced garlic",
"stick butter",
"yellow onion",
"french bread",
"worcestershire sauce",
"gruyere cheese",
"low sodium chicken broth",
"dry white wine"
);
rating = 0;
recipeName = "French Onion Soup";
smallImageUrls = (
"http://i.yummly.com/French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364-1512.s.jpg",
"http://i.yummly.com/French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364-1199.s.jpg",
"http://i.yummly.com/French-Onion-Soup-The-Pioneer-Woman-Cooks-_-Ree-Drummond-41364-220.s.jpg"
);
sourceDisplayName = "The Pioneer Woman";
totalTimeInSeconds = 0;
},
{
attributes = {
course = (
"Main Dishes"
);
};
flavors = {
bitter = 1;
meaty = "0.1666666666666667";
piquant = 0;
salty = 1;
sour = "0.1666666666666667";
sweet = "0.3333333333333333";
};
id = "Awesome-Slow-Cooker-Pot-Roast-Allrecipes";
ingredients = (
"onion soup mix",
"condensed cream of mushroom soup",
"pot roast",
water
);
rating = "4.69";
recipeName = "Awesome Slow Cooker Pot Roast";
smallImageUrls = (
"http://i2.yummly.com/Awesome-Slow-Cooker-Pot-Roast-Allrecipes-2.s.png",
"http://i.yummly.com/Awesome-Slow-Cooker-Pot-Roast-Allrecipes-58919.s.png"
);
sourceDisplayName = AllRecipes;
totalTimeInSeconds = 29400;
},
{
attributes = {
course = (
Soups
);
};
flavors = {
bitter = "0.1666666666666667";
meaty = "0.1666666666666667";
piquant = "0.6666666666666666";
salty = "0.1666666666666667";
sour = "0.1666666666666667";
sweet = "0.1666666666666667";
};
id = "Chicken-Soup-for-Knaidelach-The-Shiksa-Blog-48854";
ingredients = (
"sea salt",
"bay leave",
onions,
giblets,
"fresh dill",
"curly-leaf parsley",
"whole cloves",
"chopped leaves",
"black peppercorns",
carrot
);
rating = 0;
recipeName = "Chicken Soup for Knaidelach";
smallImageUrls = (
"http://i.yummly.com/Chicken-Soup-for-Knaidelach-The-Shiksa-Blog-48854-10792.s.png",
"http://i.yummly.com/Chicken-Soup-for-Knaidelach-The-Shiksa-Blog-48854-10711.s.png",
"http://i.yummly.com/Chicken-Soup-for-Knaidelach-The-Shiksa-Blog-48854-10617.s.png"
);
sourceDisplayName = "The Shiksa in the Kitchen";
totalTimeInSeconds = 10800;
},
{
attributes = {
course = (
Soups
);
cuisine = (
American
);
};
flavors = "<null>";
id = "Chicken-Soup-The-Pioneer-Woman-200156";
ingredients = (
ribs,
carrots,
chicken,
"bay leaf",
salt,
parsnips,
"black pepper",
onion,
"chicken broth"
);
rating = 0;
recipeName = "Chicken Soup";
smallImageUrls = (
"http://i.yummly.com/Chicken-Soup-The-Pioneer-Woman-200156-39944.s.png"
);
sourceDisplayName = "The Pioneer Woman";
totalTimeInSeconds = 0;
},