1

I am new to JSON and iOS, I have some json data that I want to load into an array, This is the json data

 {
  "items": [
         {
         "name": "abc",
         "description": "cheeseburger",
         },
         {
         "name": "def",
         "description": "ostrichburger",
         },
         {
         "name": "zxc",
         "description": "sh1tjustgotreal",
         },
         {
         "name": "scfs",
         "description": "mylifeforaiur",
         }
         ]
  }

Now I keep on getting dictionaries with dictionaries? Why is that?

On another note, If I can modify the structure of this json cos I really just want to access the inner nodes ( abc, def ) what would I change in it to make it simpler for me and others to use it? Can I get rid of the "items" node?

sleepy_ios
  • 445
  • 2
  • 4
  • 16
  • 3
    You have a dictionary that contains a single key who's value is an array of dictionaries. That's why. – Abizern Jun 11 '13 at 02:23
  • http://stackoverflow.com/questions/15180036/putting-json-into-an-array/15181743#15181743 – LE SANG Jun 11 '13 at 02:32

1 Answers1

0

When the data on the sender's end is structured as a collection of named fields, you get back a dictionary for each group of named fields. In this particular case, it looks like the outermost object has one field, which is a collection (i.e. a list or an array) of objects that each have a name and description. In other words, the sender sends you something like this:

@interface Item
@property (readwrite, copy) NSString* name;
@property (readwrite, copy) NSString* description;
@end

@interface MyObject
// This array contains objects of type Item
@property (readwrite) NSArray *items;
@end
Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523