I’m still noob with objective c code (PHP background). So I’m building this iphone app that connects to a web service. So far I’ve managed to retrieve JSON results and parse it through SBJson. However my problem is the array looks more or less like this:
MP = {
name = "Muscle Power";
desc = "";
price = "100";
};
A9 = {
name = "Armotech 9000";
desc = "";
price = "200";
};
T10 = {
name = "Titanium 10";
desc = "";
price = "300";
};
How do I get the value of the keys? as they are the codes to each item.
Plan to display it in UITableview.
First of all, the data structure you’re referring to is a dictionary, or
NSDictionaryin Objective-C. Whereas many languages use the termarrayto refer to a list of objects, PHP arrays are ordered maps with keys and values.NSDictionaryprovides a method calledallKeys, which returns anNSArrayof the keys in the dictionary. For example:Although this answer isn’t specific to
SBJson, if I recall correctly JSON results are returned asNSDictionaryobjects in that library, so you should be able to useallKeys. Hope this helps!