有没有办法在PHP中将json转换为xml? [英] Is there any way to convert json to xml in PHP?
本文介绍了有没有办法在PHP中将json转换为xml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在PHP
中将json
转换为xml
?我知道 xml 到 json 很有可能.
Is there any way to convert json
to xml
in PHP
? I know that xml to json is very much possible.
推荐答案
如果你愿意使用 来自 PEAR 的 XML Serializer,您可以通过两个简单的步骤将 JSON 转换为 PHP 对象,然后将 PHP 对象转换为 XML:
If you're willing to use the XML Serializer from PEAR, you can convert the JSON to a PHP object and then the PHP object to XML in two easy steps:
include("XML/Serializer.php");
function json_to_xml($json) {
$serializer = new XML_Serializer();
$obj = json_decode($json);
if ($serializer->serialize($obj)) {
return $serializer->getSerializedData();
}
else {
return null;
}
}
这篇关于有没有办法在PHP中将json转换为xml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文