Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Deserialization of an array/list

Luc0Luc0 Posts: 15Registered Users
edited February 2011 in iPhone SDK Development
Hey Guys!

I need some information about deserialization...I used the forum search and also tried to get some examples with google, but I was not successful.

I created a XML file with this structure:
<items>
<item>
     <name>Name</name>
     <ingredients>
          <one>ingredientOne</one>
          <tow>ingredientTwo</two>
      </ingredients>
</item>
<item>
     <name>Name2</name>
     <ingredients>
          <one>ingredientOne2</one>
          <tow>ingredientTwo2</two>
      </ingredients>
</item>
</items>
I just need the deserialization, because the data doesn't change! How do I do it? Does anyone have any sample code?

Or am I studid and there are much more easier ways? I want to store it in a XML file because there are about 100 items and every item has got another array with N ingredients. I could "store it programatically", but I hate that...

So I want to deserialize the xml into an array or a list...

I don't have any sample code yet because I have any information :/

Hope to get some help, thanks!!

Luc0
Post edited by Luc0 on

Replies

  • Duncan CDuncan C Posts: 9,019Tutorial Authors, Registered Users @ @ @ @ @ @ @
    edited February 2011
    Luc0 wrote: »
    Hey Guys!

    I need some information about deserialization...I used the forum search and also tried to get some examples with google, but I was not successful.

    I created a XML file with this structure:
    <items>
    <item>
         <name>Name</name>
         <ingredients>
              <one>ingredientOne</one>
              <tow>ingredientTwo</two>
          </ingredients>
    </item>
    <item>
         <name>Name2</name>
         <ingredients>
              <one>ingredientOne2</one>
              <tow>ingredientTwo2</two>
          </ingredients>
    </item>
    </items>
    
    I just need the deserialization, because the data doesn't change! How do I do it? Does anyone have any sample code?

    Or am I studid and there are much more easier ways? I want to store it in a XML file because there are about 100 items and every item has got another array with N ingredients. I could "store it programatically", but I hate that...

    So I want to deserialize the xml into an array or a list...

    I don't have any sample code yet because I have any information :/

    Hope to get some help, thanks!!

    Luc0


    The easy way to do this is to use property lists.


    Save to a file using the NSArray method writeToFile:atomically:

    Then read the data back from the file using arrayWithContentsOfFile:

    if you want to serialize/deserialize an array in memory, use NSKeyedArchiver instead. Look at the method archivedDataWithRootObject:

    That method will return an NSData object that contains a serialized version of the contents of your array.

    Note that the property list approach will only work if the entire object graph contained in the array consists of property list objects (NSData, NSDate, NSNumber, NSString, NSArray, or NSDictionary)

    If you want to save other types of objects to a property list, you need to convert them to NSData by supporting the NSCoding protocol.
    Regards,
    Duncan C
    WareTo

    widehead.gif
    Animated GIF created with Face Dancer, available for free in the app store.

    I'm available for one-on-one help at CodeMentor
  • Luc0Luc0 Posts: 15Registered Users
    edited February 2011
    Hey Duncan C!

    So that means that I should add the data (Yes, it consists only of NSStrings) programatically to an array and than save it to the property file?

    I'll try that today and let you know, thanks!

    Luc0
Sign In or Register to comment.