我正在使用Symfony 3.3
序列化程序。这段代码:
$serialized = $this->serializer->serialize($input, "json");
返回:
{
"title": "dsd",
"description": null,
"source": null,
"tags": null,
"objectId": null,
"attributes": {
"sdffds": "sdffsdfsd",
"fsfdsfd": "sdfsdfsdf"
},
"features": [],
"lifecycleStart": null,
"lifecycleEnd": null,
"attachments": {
"20170625194534-595012dee26c8": {
"original": "favicon (1).ico",
"filename": "favicon (1).ico",
"size": "318",
"title": null,
"description": null,
"reader": null
}
}
}
不可思议,正在运行
$serialized = $this->serializer->serialize($input, "xml");
会抛出异常:
Uncaught PHP Exception DOMException: "Invalid Character Error" at /www/site/ui/vendor/symfony/symfony/src/Symfony/Component/Serializer/Encoder/XmlEncoder.php line 454
我很确定我没有包含任何有趣的角色。你知道我做错了什么或者它是一个symfony bug吗?
答案 0 :(得分:1)
这可能是因为20170625194534-595012dee26c8
。 XML元素名称不能以数字开头。请参阅XML.com上的The Naming of Parts文章。