1

I want to use php serialized data in ionic v1, I am getting json object like this :

"a:2:{s:15:"default_account";b:0;s:14:"accessory_skus";a:2:{i:138;a:4:{s:2:"id";s:3:"138";s:17:"accessory_sku_key";s:9:"UNT-1/2OD";s:8:"quantity";s:4:"5.00";s:5:"units";s:4:"Nos.";}i:375;a:4:{s:2:"id";s:3:"375";s:17:"accessory_sku_key";s:6:"100359";s:8:"quantity";s:5:"12.00";s:5:"units";s:4:"Nos.";}}}"

how to convert it to pure json..? I tried json.parse() I didnt get expected result.

Bahman Parsa Manesh
  • 2,314
  • 3
  • 16
  • 32
Anant kamat
  • 373
  • 3
  • 13
  • 1
    Its not a valid JSON String to parse it using JSON.parse(). – Manish Balodia Jul 31 '18 at 12:48
  • 3
    From php side you can use json_encode and in javascript you can get json – Paresh Gami Jul 31 '18 at 12:49
  • 2
    I don't think you can (easily) de-serialize php-serialized data in javascript. There might be a library I don't know of. Can't you [unserialize()](http://php.net/manual/en/function.unserialize.php) it in php first? – Jeff Jul 31 '18 at 12:49
  • here's a library/script that looks like doing the job in js: http://locutus.io/php/var/unserialize/ – Jeff Jul 31 '18 at 12:51
  • 2
    _"i am getting json object like this"_ - no, it's not a json "object", it's a serialized representation (a string) of php objects. – Jeff Jul 31 '18 at 12:55
  • 1
    As others suggested, you can use unserialize, but, if this is the only purpose of storing a serialized object, I suggest you consider converting it to JSON in first place instead of serializing it. – Nima Jul 31 '18 at 13:27

0 Answers0