可能是一个奇怪的问题,因为我找不到任何参考,但是,我正在使用Wordpress并创建一个自定义插件,但是,因为我还在开发它,它没有安装,只是在Wordpress框架内构建。
我有一个stdClass,它已被转换为字符串并放在localStorage中。这是字符串的样子:
> stdClass Object ( [flow_uuid] => 178ee7f1-8708-417f-b5e6-970bab44ec37
> [flow] => 26929 [run] => 5034279 [contact] =>
> ec73659b-b270-453c-8170-c190667917d7 [completed] => [values] => Array
> ( ) [steps] => Array ( [0] => stdClass Object ( [node] =>
> 83e332e0-a456-449f-a4f6-cee688f9395b [arrived_on] =>
> 2015-10-12T07:30:30.342Z [left_on] => 2015-10-12T07:30:30.470Z [text]
> => Hello! Good Morning Mr T How's U This morning? [type] => A [value] => None ) [1] => stdClass Object ( [node] => f85ed8a8-e745-495e-8eaf-1e6cfdbadf97 [arrived_on] =>
> 2015-10-12T07:30:30.470Z [left_on] => [text] => [type] => R [value] =>
> None ) ) [created_on] => 2015-10-12T07:30:30.235Z [modified_on] =>
> 2015-10-12T07:30:30.250Z [expires_on] => [expired_on] => [runtime] =>
> 12 - 10 @ 07 hour [runComplete] => false )
PHP中的代码是一个循环,如下所示:
<td style="text-align: center">
<a class="button" href="index.php/?page_id=954" name="view_runlist" rel="<?php print_r($time); ?>" >View</a>
</td>
点击链接(按钮)后,它会在Javascript:
中触发jQuery(document).on('click', '[name=view_runlist]', function() {
localStorage.setItem('time', jQuery(this).attr('rel'));
});
然后在另一个链接页面上(page_id = 954)我在PHP中有这个:
$time = "<script>document.write(localStorage.getItem('time'));</script>";
但是这只给了我一个字符串,我一直在用explode
和str_split
测试它,试着让它回到一个对象。
有没有办法将字符串转换回对象,并能够将其用作对象?
提前致谢