1

hey i have a serialize array from database like this

a:3:{i:0;s:2:"12";i:1;s:2:"13";i:2;s:2:"14";}

all i want to parse that array with javascript. i have doing JSON.parse() but still not working , can you help me? if in PHP there's unserialize($var) is there possible unsrialize(var) in javascript ? by the way i use nodejs express.

5
  • 1
    Its not a valid JSON. Hence JSON.parse is failing Commented May 9, 2017 at 7:03
  • This is not a valid json, are you sure you receive this data ? Commented May 9, 2017 at 7:03
  • 1
    How do you end up with that data? It doesn't resemble anything I've ever seen. Commented May 9, 2017 at 7:03
  • i'm doing that serialize in PHP, but i have application which is nodejs, so i need to parse that serialize array. Commented May 9, 2017 at 7:05
  • Please post the code that retrieve the data from the database. Where do you see this data ? Did you use console.log() ? Commented May 9, 2017 at 7:16

2 Answers 2

0

This is not json.Some CMS like wordpress use it to store data. you have to explode it php or split it in javascript.

Sign up to request clarification or add additional context in comments.

Comments

-1

You can use this lib:

https://github.com/naholyr/js-php-unserialize

But in general, I can't understand why do you need this. Just convert in to the JSON object in PHP, then work without troubles with it in JS.

4 Comments

I can't understand poeple who can't understand that web is complex and not all developpers are aware of good practices. You may need to treat data from another app, which return a serialized php array in a JS APP. Basicaly the developper should have return a json object, it's not the case we have to deal with it. So the end of your response is useless, as it's for so many stack responses.
@DrK, not sure what you want to point out with your comment. The answer was helpful to the user (it has a solution to the problem), and it contains suggestion, that it's not wise to use PHP internal format for the external communication; if you have a better suggestion, please write your own answer, if you have some suggestions on how to make the answer more clear, please clarify
It was not completely helpfull the end of your statement was not helping at all. I had the case where I had to use this library, if your stuck with JS tell me what's the point telling the user to use PHP ? Don't you think if the user had the chance to use php he would have post this thread ?
@DrK, then read comments under the question attentively; user clearly had access to the backend since he said "i'm doing that serialize in PHP", that's why was that advice, to not use php-serialized data for the stored items; if you hit this question because you have similar problem you can create your own question

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.