在Javascript中反序列化PHP数组 [英] Unserialize PHP Array in Javascript

查看:183
本文介绍了在Javascript中反序列化PHP数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有行序列化阵列的负载,我打算请求,并将其传递给的JavaScript

现在的问题是 - 是否有可能反序列化用JavaScript,而不是PHP?

否则我将不得不加载所有行,循环他们和反序列化它们,并将它们分配给一个临时的PHP数组,然后json_en code回的JavaScript似乎非常低效的,如果我可以给还在连载因此数据该JavaScript可以反序列化数据时,它需要。

有一个内置的JavaScript函数做,否则我将不得不循环在PHP中的行之前,我连接code呢?

请注意,我没有使用jQuery的。

编辑: 我的序列化数据从我的表PHP的例子:

  A:8:{I:0;一:2:{I:0;我:10; I:1;我:11;} I:1; A:2 :{I:0; I:9; I:1;我:11;} I:2;一:2:
{I:0; I:8; I:1;我:11;} I:3; 2:{I:0; I:8; I:1;我:10;}我:4;一: 2:{I:0; I:8; I:1;我:9;}我:5;一:2:
{I:0; I:8; I:1;我:8;}我:6;一:2:{I:0; I:8; I:1;我:7;}我:7;一个: 2:{I:0; I:8; I:1;我:6;}}
 

解决方案

包装 json_en code 围绕反序列化

 回声json_en code(反序列化($阵列));
 

I have a table with a load of rows of serialized arrays that I plan to request and pass it to JavaScript.

The problem is - is it possible to unserialize with JavaScript rather than PHP ?

Otherwise I will have to load all the rows, loop them and unserialize them and assign them to a temporary PHP array and then json_encode it back to JavaScript which seems highly inefficient if I can send the data still serialized so that JavaScript can unserialize the data when it needs to.

Is there a built in Javascript function that does it or will I have to loop the rows in PHP before I encode it?

Note I am not using jQuery.

EDIT: Example of my serialized data in PHP from my table:

a:8:{i:0;a:2:{i:0;i:10;i:1;i:11;}i:1;a:2:{i:0;i:9;i:1;i:11;}i:2;a:2:
{i:0;i:8;i:1;i:11;}i:3;a:2:{i:0;i:8;i:1;i:10;}i:4;a:2:{i:0;i:8;i:1;i:9;}i:5;a:2:
{i:0;i:8;i:1;i:8;}i:6;a:2:{i:0;i:8;i:1;i:7;}i:7;a:2:{i:0;i:8;i:1;i:6;}}

解决方案

wrap json_encode around unserialize

echo json_encode( unserialize( $array));

这篇关于在Javascript中反序列化PHP数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆