Uncaught exception ' exception ' with message ' serialization of ' simplexmlelement

Source: Internet
Author: User
Tags stack trace
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.
Handle a period
SimpleXMLElement Object
(
[Item_cats] = SimpleXMLElement Object
(
[@attributes] = = Array
(
[List] = True
)

[Item_cat] = = Array
(

......
)
)
)
Convert it to an array
Local test can, post-upload error:
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: Deal_taobao_data (Object (simplexmlelement))
#2 {main}
Thrown in/web/taobao.php on line 328
There are no friends who know the root of the problem.


Reply to discussion (solution)

Local test can be???
I don't blame you for joking.

It is true that the test is correct ...

Local test can be???
I don't blame you for joking.
Returns the full array.

Paste out your sample data

Paste out your sample data
SimpleXMLElement Object
(
[Item_cats] = SimpleXMLElement Object
(
[@attributes] = = Array
(
[List] = True
)

[Item_cat] = = Array
(
[0] = = simplexmlelement Object
(
[CID] = 50013865
[Is_parent] = False
[Name] + + necklace
[Parent_cid] = 50013864
)

[1] = = SimpleXMLElement Object
(
[CID] = 50013868
[Is_parent] = False
[name]/= pendant/Pendant
[Parent_cid] = 50013864
)

[2] = = SimpleXMLElement Object
(
[CID] = 50014227
[Is_parent] = True
[Name] + earrings
[Parent_cid] = 50013864
)

[3] = = SimpleXMLElement Object
(
[CID] = 50013869
[Is_parent] = False
[name] + = Bracelet
[Parent_cid] = 50013864
)

[4] = = SimpleXMLElement Object
(
[CID] = 50013870
[Is_parent] = False
[name] + = Bracelet
[Parent_cid] = 50013864
)

[5] = = SimpleXMLElement Object
(
[CID] = 50013871
[Is_parent] = False
[name] + = Anklet
[Parent_cid] = 50013864
)

[6] = = SimpleXMLElement Object
(
[CID] = 50013875
[Is_parent] = False
[Name] = ring/Ring
[Parent_cid] = 50013864
)

[7] = = SimpleXMLElement Object
(
[CID] = 50013876
[Is_parent] = False
[Name] + brooch
[Parent_cid] = 50013864
)

[8] = = SimpleXMLElement Object
(
[CID] = 50013877
[Is_parent] = False
[Name] + Ornaments
[Parent_cid] = 50013864
)

[9] = = SimpleXMLElement Object
(
[CID] = 50013878
[Is_parent] = False
[Name] + Hair Ornaments
[Parent_cid] = 50013864
)

[Ten] = SimpleXMLElement Object
(
[CID] = 50013879
[Is_parent] = False
[name] + DIY Jewelry Accessories
[Parent_cid] = 50013864
)

[One] = SimpleXMLElement Object
(
[CID] = 50013880
[Is_parent] = False
[Name] + Jewellery maintenance identification
[Parent_cid] = 50013864
)

[[] = SimpleXMLElement Object
(
[CID] = 50013881
[Is_parent] = False
[Name] + Jewelry box/display stand
[Parent_cid] = 50013864
)

[+] = simplexmlelement Object
(
[CID] = 50013882
[Is_parent] = False
[Name] = other Jewellery
[Parent_cid] = 50013864
)

)

)

)
1

Code that was successfully returned by the local test (part omitted):
Array
(
[Item_cats] = = Array
(
[@attributes] = = Array
(
[List] = True
)

[Item_cat] = = Array
(
[0] = = Array
(
[CID] = 50013865
[Is_parent] = False
[Name] + + necklace
[Parent_cid] = 50013864
)

[1] = = Array
(
[CID] = 50013868
[Is_parent] = False
[name]/= pendant/Pendant
[Parent_cid] = 50013864
)

[2] = = Array
(
[CID] = 50014227
[Is_parent] = True
[Name] + earrings
[Parent_cid] = 50013864
)

[3] = = Array
(
[CID] = 50013869
[Is_parent] = False
[name] + = Bracelet
[Parent_cid] = 50013864
)


)

)

)
1

If there is a substitute code, can also, can solve the problem on the line.

1. SimpleXMLElement cannot be serialized
Uncaught exception ' exception ' with message ' serialization of ' simplexmlelement ' are not allowed '
2, even if it is possible, by
echo Serialize (Array (1));
A:1:{i:0;i:1;}
And I'm not replacing you like that.

1. SimpleXMLElement cannot be serialized
Uncaught exception ' exception ' with message ' serialization of ' simplexmlelement ' are not allowed '
2, even if it is possible, by
echo Serialize (Array (1));
A:1:{i:0;i:1;}
And I'm not replacing you like that.
Solve yourself, change a function!
function Deal_taobao_data ($data) {
$arrstrs =json_encode ($data);
$arrstr =json_decode ($arrstrs, true);
return $arrstr;
}

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.