I'm using json-framework to create a NSDictionary out of a JSON response. That much works wonderfully.
Now, within this JSON payload are one or more objects - let's call them X. Sort of like this in XML:
<OBJECTS>
<X>
...
</x>
<X>
...
</X>
<X>
...
</X>
</OBJECTS>
When I look in the aforementioned NSDictionary object for all Xs, like so:
NSDictionary *results = [[dict objectForKey:@"OBJECTS"] objectForKey:@"X"];
Or even:
NSDictionary *results = [dict valueForKeyPath:@"OBJECTS.X"];
I get, according to gdb, a NSCFArray of NSDictionary objects. (Yes, I smell something funny here too, but more on this in a moment.)
When there is only one object named X, I get back an honest-to-goodness NSDictionary.
So ... what should I do to make this behave consistently, no matter how many Xs there are?
At first glance, I'd think I just change results to be NSArray *, but what happens when I want to fast enumerate over the results? Right now I do this:
for (NSDictionary *result in results)
In the NSCFArray case (multiple Xs), I get back an individual NSDictionary for each X. In the single X case, I get back the one NSDictionary, except now my perspective is one level too deep. In other words, instead of this (contrived example):
(gdb) po results
<NSCFArray 0xd4a940>(
{
foo = {
bar = "something";
};
}
{
foo = {
bar = "something else";
};
}
)
I get this:
(gdb) po results
{
foo = {
bar = "something";
};
}
Clues welcome/appreciated! You may even ask if it's necessary to have to break this apart at all, but for now let's suppose this trip is really necessary. (Still, I'm happy to be persuaded otherwise, if someone feels strongly enough about it.)
Ultimately, at the end of the day, I want to have a NSArray of NSDictionary objects.