0

I want to deserialize data from php serialize array in node js

I found in many questions use JSON.stringify() to serialize and for deserialize use JSON.parse but unable to do the same and not find any solution for the same too

My serialize data:-

a:1:{i:0;a:4:{s:10:"first_name";s:7:"Vikas";s:11:"last_name";s:6:"Kohli";s:8:"end_date";s:10:"2017-06-12";s:16:"position";s:19:"Software Developer";}}

How to deserialize this array ?

I found to slove the same using

  1. http://locutus.io/php/var/unserialize/ but I didn't saw any implementation for the same.
  2. https://github.com/naholyr/js-php-unserialize --- ( Compatibility issues -This library has been tested server-side only. For example it uses [].reduce, so it may not work on some browsers. Do not hesitate to make pull requests to fix it for you favorite browsers :) that's why not used

Also when I used the second method, then it results like

{ '0': 
   { first_name: 'Vikas',
     last_name: '899.99',
     end_date: '2017-06-12',
     position: 'Software Developer' 
    }
}

Now how would I fetch the data from that if I used as there can be data like 0, 1 ,2 and so on

I hope I am able to understand my question.

7
  • 2
    What's the use case here? Can you simply use json_encode instead of serialize? Commented Jun 21, 2017 at 14:11
  • well, just a simple google whould show this javascript php deserialize library. Commented Jun 21, 2017 at 14:12
  • 1
    Please show the PHP code with which you produce this. There are certainly better ways to do this than to try to decode this in JavaScript. Commented Jun 21, 2017 at 14:15
  • 1
    "I hope I am able to understand my question.": fingers crossed. Commented Jun 21, 2017 at 14:38
  • @trincot In php, deserialize like this $data11=unserialize(($row['data'])); Commented Jun 21, 2017 at 14:39

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.