UncaughtexceptionExceptionwithmessageSerializationofSimpleXMLElement function deal_taobao_data ($ data ){
$ Data = serialize ($ data );
$ Data = str_replace ('O: 16: "SimpleXMLElement" ', 'A', $ data );
$ Arrstr = unserialize ($ data );
Return $ arrstr;
}
This is my code
Process a segment
SimpleXMLElement Object
(
[Item_cats] => SimpleXMLElement Object
(
[@ Attributes] => Array
(
[List] => true
)
[Item_cat] => Array
(
......
)
)
)
Convert it to an array
The local test is acceptable. an error is reported after the upload:
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
Does anyone know the root cause of this problem.
Reply to discussion (solution)
Can I perform a local test ???
Don't blame you!
The test is correct...
Can I perform a local test ???
Don't blame you!
Returns the complete array.
Paste your sample data
Paste your sample data
SimpleXMLElement Object
(
[Item_cats] => SimpleXMLElement Object
(
[@ Attributes] => Array
(
[List] => true
)
[Item_cat] => Array
(
[0] => SimpleXMLElement Object
(
[Cid] = & gt; 50013865
[Is_parent] => false
[Name] => necklace
[Parent_cid] = & gt; 50013864
)
[1] => SimpleXMLElement Object
(
[Cid] = & gt; 50013868
[Is_parent] => false
[Name] => pendant/pendant
[Parent_cid] = & gt; 50013864
)
[2] => SimpleXMLElement Object
(
[Cid] = & gt; 50014227
[Is_parent] => true
[Name] => earrings
[Parent_cid] = & gt; 50013864
)
[3] => SimpleXMLElement Object
(
[Cid] = & gt; 50013869
[Is_parent] => false
[Name] => bracelet
[Parent_cid] = & gt; 50013864
)
[4] => SimpleXMLElement Object
(
[Cid] = & gt; 50013870
[Is_parent] => false
[Name] => bracelet
[Parent_cid] = & gt; 50013864
)
[5] => SimpleXMLElement Object
(
[Cid] = & gt; 50013871
[Is_parent] => false
[Name] => foot chain
[Parent_cid] = & gt; 50013864
)
[6] => SimpleXMLElement Object
(
[Cid] = & gt; 50013875
[Is_parent] => false
[Name] => ring/ring
[Parent_cid] = & gt; 50013864
)
[7] => SimpleXMLElement Object
(
[Cid] = & gt; 50013876
[Is_parent] => false
[Name] => brooch
[Parent_cid] = & gt; 50013864
)
[8] => SimpleXMLElement Object
(
[Cid] = & gt; 50013877
[Is_parent] => false
[Name] => Ornaments
[Parent_cid] = & gt; 50013864
)
[9] => SimpleXMLElement Object
(
[Cid] = & gt; 50013878
[Is_parent] => false
[Name] => hair accessories
[Parent_cid] = & gt; 50013864
)
[10] => SimpleXMLElement Object
(
[Cid] = & gt; 50013879
[Is_parent] => false
[Name] => DIY jewelry accessories
[Parent_cid] = & gt; 50013864
)
[11] => SimpleXMLElement Object
(
[Cid] = & gt; 50013880
[Is_parent] => false
[Name] => jewelry maintenance qualification
[Parent_cid] = & gt; 50013864
)
[12] => SimpleXMLElement Object
(
[Cid] = & gt; 50013881
[Is_parent] => false
[Name] => jewelry box/Display rack
[Parent_cid] = & gt; 50013864
)
[13] => SimpleXMLElement Object
(
[Cid] = & gt; 50013882
[Is_parent] => false
[Name] => other jewelry
[Parent_cid] = & gt; 50013864
)
)
)
)
1
Code returned for successful local test (omitted part ):
Array
(
[Item_cats] => Array
(
[@ Attributes] => Array
(
[List] => true
)
[Item_cat] => Array
(
[0] => Array
(
[Cid] = & gt; 50013865
[Is_parent] => false
[Name] => necklace
[Parent_cid] => 50013864.
)
[1] => Array
(
[Cid] = & gt; 50013868
[Is_parent] => false
[Name] => pendant/pendant
[Parent_cid] = & gt; 50013864
)
[2] => Array
(
[Cid] = & gt; 50014227
[Is_parent] => true
[Name] => earrings
[Parent_cid] = & gt; 50013864
)
[3] => Array
(
[Cid] = & gt; 50013869
[Is_parent] => false
[Name] => bracelet
[Parent_cid] = & gt; 50013864
)
)
)
)
1
If there is code that can be replaced, you can solve the problem.
1. SimpleXMLElement cannot be serialized
Uncaught exception 'exception' with message 'serialization of 'simplexmlelement' is not allowed'
2. even if yes
Echo serialize (array (1 ));
A: 1: {I: 0; I: 1 ;}
It's not replaced like you do.
1. SimpleXMLElement cannot be serialized
Uncaught exception 'exception' with message 'serialization of 'simplexmlelement' is not allowed'
2. even if yes
Echo serialize (array (1 ));
A: 1: {I: 0; I: 1 ;}
It's not replaced like you do.
Solved it by yourself. change the function!
Function deal_taobao_data ($ data ){
$ Arrstrs = json_encode ($ data );
$ Arrstr = json_decode ($ arrstrs, true );
Return $ arrstr;
}