So I've got an NSDictionary
that holds JSON data from doing the following:
NSDictionary* dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&someError];
And when I NSLog my dictionary, I get the output below.
2015-06-11 17:13:49.699 AmigoDash[57994:1195566] (
{
"_id" = {
"$id" = 5579fde2e4b0588ab009f841;
};
hours = "10-11";
image = imageURL;
name = "Boleskine Bistro";
},
{
"_id" = {
"$id" = 5579fe1fe4b0588ab009f84a;
};
hours = "9-11";
image = imageURL;
name = Amrikos;
}
)
The problem I'm facing now is trying to iterate through the dictionary. When I try to do it, the code crashes. I'm new to working with JSON and iOS in general. Kind of overwhelmed. I ultimately need to get the name and image information from each unique object in the dictionary, so I have to iterate through the dictionary.
You need to understand the basics of JSON components and how the are parsed into iOS. I will give you a simple example I got here. This I generally used for parsing JSON
This is the general kind of JSON you will get.
These are parsed as follows
[]
denote anarray
which is parsed into aNSArray
{}
denote andictionary
which is parsed into aNSDictionary
true
orfalse
is aBOOL
int
,NSInteger
,NSNumber
, etc""
is forNSString
Now you should first pay attention to the structure, like what is inside what. And Then parse accordingly.
Let say for Above Example. The outermost object is an
NSDictionary
({}
).Inside we have an
NSArray
([]
)Each of
testFeeds
object is anNSDictionary
. This we we proceed from outermost to innermost object.