function deal_taobao_data($data){
$data = serialize($data);
$data = str_replace('o:16:simplexmlelement', 'a', $data);
$arrstr = unserialize($data);
return $arrstr;
}
这是我的代码
处理一段
simplexmlelement object
(
[item_cats] => simplexmlelement object
(
[@attributes] => array
(
[list] => true
)
[item_cat] => array
(
……
)
)
)
将其转化为数组
本地测试可以,上传后报错误:
fatal error: uncaught exception 'exception' with message 'serialization
of 'simplexmlelement' is not allowed' in /web/taobao.php:328
stack trace:
#0 /web/taobao.php(328): serialize(object(simplexmlelement))
#1 /web/taobao.php(50): deal_taobao_data(object(simplexmlelement))
#2 {main}
thrown in /web/taobao.php on line 328
有没有朋友知道这一问题根源的。
回复讨论(解决方案) 本地测试可以???
开玩笑不怪你
确实测试无误。。。
本地测试可以???
开玩笑不怪你
返回了完整数组。
贴出你的示例数据
贴出你的示例数据
simplexmlelement object
(
[item_cats] => simplexmlelement object
(
[@attributes] => array
(
[list] => true
)
[item_cat] => array
(
[0] => simplexmlelement object
(
[cid] => 50013865
[is_parent] => false
[name] => 项链
[parent_cid] => 50013864
)
[1] => simplexmlelement object
(
[cid] => 50013868
[is_parent] => false
[name] => 项坠/吊坠
[parent_cid] => 50013864
)
[2] => simplexmlelement object
(
[cid] => 50014227
[is_parent] => true
[name] => 耳饰
[parent_cid] => 50013864
)
[3] => simplexmlelement object
(
[cid] => 50013869
[is_parent] => false
[name] => 手链
[parent_cid] => 50013864
)
[4] => simplexmlelement object
(
[cid] => 50013870
[is_parent] => false
[name] => 手镯
[parent_cid] => 50013864
)
[5] => simplexmlelement object
(
[cid] => 50013871
[is_parent] => false
[name] => 脚链
[parent_cid] => 50013864
)
[6] => simplexmlelement object
(
[cid] => 50013875
[is_parent] => false
[name] => 戒指/指环
[parent_cid] => 50013864
)
[7] => simplexmlelement object
(
[cid] => 50013876
[is_parent] => false
[name] => 胸针
[parent_cid] => 50013864
)
[8] => simplexmlelement object
(
[cid] => 50013877
[is_parent] => false
[name] => 摆件
[parent_cid] => 50013864
)
[9] => simplexmlelement object
(
[cid] => 50013878
[is_parent] => false
[name] => 发饰
[parent_cid] => 50013864
)
[10] => simplexmlelement object
(
[cid] => 50013879
[is_parent] => false
[name] => diy饰品配件
[parent_cid] => 50013864
)
[11] => simplexmlelement object
(
[cid] => 50013880
[is_parent] => false
[name] => 首饰保养鉴定
[parent_cid] => 50013864
)
[12] => simplexmlelement object
(
[cid] => 50013881
[is_parent] => false
[name] => 首饰盒/展示架
[parent_cid] => 50013864
)
[13] => simplexmlelement object
(
[cid] => 50013882
[is_parent] => false
[name] => 其它首饰
[parent_cid] => 50013864
)
)
)
)
1
本地测试成功返回的代码(省略了一部分):
array
(
[item_cats] => array
(
[@attributes] => array
(
[list] => true
)
[item_cat] => array
(
[0] => array
(
[cid] => 50013865
[is_parent] => false
[name] => 项链
[parent_cid] => 50013864
)
[1] => array
(
[cid] => 50013868
[is_parent] => false
[name] => 项坠/吊坠
[parent_cid] => 50013864
)
[2] => array
(
[cid] => 50014227
[is_parent] => true
[name] => 耳饰
[parent_cid] => 50013864
)
[3] => array
(
[cid] => 50013869
[is_parent] => false
[name] => 手链
[parent_cid] => 50013864
)
)
)
)
1
如果有能够代替的代码,也可以,能解决问题就行。
1、simplexmlelement 不可被序列化
uncaught exception 'exception' with message 'serialization of 'simplexmlelement' is not allowed'
2、即便是可以,由
echo serialize(array(1));
a:1:{i:0;i:1;}
也不是像你那样替换
1、simplexmlelement 不可被序列化
uncaught exception 'exception' with message 'serialization of 'simplexmlelement' is not allowed'
2、即便是可以,由
echo serialize(array(1));
a:1:{i:0;i:1;}
也不是像你那样替换
自己解决了,换一个函数!
function deal_taobao_data($data){
$arrstrs=json_encode($data);
$arrstr=json_decode($arrstrs,true);
return $arrstr;
}