Reputation: 9
Is there any function in Delphi like "unserialize()" in PHP?
The array that I have is in string format like this:
a:6:{s:15:"info_buyRequest";a:2:{s:3:"qty";i:1;s:1 5:"super_attribute";a:2:{i:234;s:4:"2047";i:237;s: 4:"4312";}}s:15:"attributes_info";a:2:{i:0;a:2:{s: 5:"label";s:6:"Taglia";s:5:"value";s:6:"6 anni";}i:1;a:2:{s:5:"label";s:9:"TIPOLOGIA";s:5:"v alue";s:25:"Completo + Pallone Adidas";}}s:11:"simple_name";s:78:"Maglia Bacca Milan Carlos Ufficiale 2015 2016 Completo Pallone Jersey AC MILAN";s:10:"simple_sku";s:4:"-148";s:20:"product_calculations";i:1;s:13:"shipmen t_type";i:0;}
Thank you
Upvotes: 0
Views: 600
Reputation: 613491
Is there any function in Delphi like "unserialize()" in PHP?
There is nothing in the Delphi runtime library that can operate directly on a the output from PHP serialize()
. That function uses a bespoke format that is not standardised. In an ideal world you would use a widely accepted standard like JSON. Indeed PHP has support for JSON and if the serialization was instead performed with json_encode()
it would be simple to deserialize in Delphi or indeed any other mainstream language.
You will need to take one of the following options to solve your problem:
json_encode(unserialize(...))
.serialize()
.FWIW, any API that hands you the output of serialize()
is badly designed and one might consider it prudent to look for an alternative.
Upvotes: 4