Populating data to Table View from NSDictionary

Discussion in 'iOS Programming' started by b0yax, Jun 21, 2010.

  1. b0yax macrumors newbie

    Joined:
    Feb 24, 2010
    #1
    Hi,

    I've got here a sample JSON response:
    {
    1 = {
    "name" = John Depp;
    "category" = Animals;
    "descripton" = "Some texts1";
    "id" = 1;
    };
    2 = {
    "name" = Shi;
    "category" = Animals;
    "description" = "some texts2";
    "id" = 2;
    };
    3 = {
    "name" = Sha;
    "category" = Animals;
    "description" = "some text3";
    "id" = 3;
    };
    }

    How I could convert this from NSDictionary to NSArray so I can populate the data objects into the table view?

    Need advise. Thanks
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    Location:
    Brobdingnag
    #2
    Get the keys as a sorted array, then enumerate the ordered keys. See the reference doc for NSDictionary, and look for methods that return sorted keys in an NSArray.

    Or just use the resulting sorted array directly, and retrieve objects by key. That is, a composition consisting of an array of sorted keys accessible by index, and the resulting key is then used to retrieve the value held in the dictionary.

    BTW, your JSON text is malformed: '=' instead of ':', missing some quotes, and contains semicolons, which JSON doesn't use. What you posted looks more like an old-style plist, but if so, that's malformed, too: missing some quotes.

    http://json.org/
     

Share This Page