Advertise here




Advertise here

Howdy, Stranger!

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

Sign In with Google Sign In with OpenID
Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.

Unserialize functionality in ios??

richammondrichammond Posts: 26Registered Users
Hi guys, i'm sure you all know the unserialze() function in PHP. I need the same thing for IOS. Basically i got a string from db field which looks like this :
a:4:{i:0;s:6:"Vincent";i:1;s:14:"Julie";i:2;s:12:"Tomas";i:3;s:10:"John";}

I would like the correct function to display the above string as : Vincent, Julie, Tomas, John.

I've looked into ios - Objective C: How to extract part of a String (e.g. start with '#') - Stack Overflow but didn't work out exactly as i wanted it :-(

Any help would be greatly appreciated.

Thanks!!
Post edited by richammond on

Replies

  • kevinyidekevinyide Posts: 249New Users
    Not sure if there is a correct function but you may want to take a look at this post.

    Hope this helps.
  • Duncan CDuncan C Posts: 8,021Tutorial Authors, Registered Users
    richammond;365073 said:
    Hi guys, i'm sure you all know the unserialze() function in PHP. I need the same thing for IOS. Basically i got a string from db field which looks like this :
    a:4:{i:0;s:6:"Vincent";i:1;s:14:"Julie";i:2;s:12:"Tomas";i:3;s:10:"John";}

    I would like the correct function to display the above string as : Vincent, Julie, Tomas, John.

    I've looked into ios - Objective C: How to extract part of a String (e.g. start with '#') - Stack Overflow but didn't work out exactly as i wanted it :-(

    Any help would be greatly appreciated.

    Thanks!!
    No, I don't know the PHP unserialze (unserialize?) command.

    In general terms, it looks like a command that takes a variable (or object) and converts it to a byte-stream. That concept exists in Cocoa as well. However, the details are different. I doubt you'll find a ready-made way to unserialize PHP variables/objects into Objective C, since they are different languages, and their data structures and constructs are different. PHP is loosely typed, for example, which is likely to cause problems in creating Objective C equivalent structures.

    You'll probably have to restrict what you put the DB fields in PHP to a specific format (or small set of possible formats), and then write Objective C code that parses that specific format into Objective C data containers.
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • richammondrichammond Posts: 26Registered Users
    Thanks!! Guess what i've done is as suggested : make sure the data being serialised is in a readable format. I wanted to go the quickest route, but seems like that one was the longest but simpler!!

    Thanks again
  • Duncan CDuncan C Posts: 8,021Tutorial Authors, Registered Users
    richammond;366033 said:
    Thanks!! Guess what i've done is as suggested : make sure the data being serialised is in a readable format. I wanted to go the quickest route, but seems like that one was the longest but simpler!!

    Thanks again
    It will probably be easier to export the data in a format like JSON that is cross-platform.

    You could also use a PHP implementation of property lists, like CFPropertyList

    Binary property lists are a whole lot faster and more efficient than text-based formats like JSON (or worse yet XML)
    Regards,

    Duncan C
    WareTo

    mug

    Animated GIF created with Face Dancer, available for free in the app store.
  • AjpatelAjpatel Posts: 2New Users

    Thanks!! Guess what i've done is as suggested : make sure the data being serialised is in a readable format. I wanted to go the quickest route, but seems like that one was the longest but simpler!!

    Thanks again

    Please elaborate your answer how did you manage this king of string parsing with objective C. I face same issues with magento api response. Did you perform string operation with this uneven structure or what ?

    Thanks in advance !!
    Post edited by Ajpatel on
  • surlacsurlac Posts: 315New Users

    Basically i got a string from db field which looks like this :
    a:4:{i:0;s:6:"Vincent";i:1;s:14:"Julie";i:2;s:12:"Tomas";i:3;s:10:"John";}

    I would like the correct function to display the above string as : Vincent, Julie, Tomas, John.

    Thanks!!

    It looks like you better roll you own deserializer. Even SOAP deserializers aren't good enough out off the box for iOS.
Sign In or Register to comment.