【问题标题】:How to echo contents of XML but in JSON format? [duplicate]如何以 JSON 格式回显 XML 的内容? [复制]
【发布时间】:2016-05-11 21:32:59
【问题描述】:

我正在尝试制作一个与http://thegamesdb.net/api/GetGamesList.php?name=dog 的内容相呼应但采用 JSON 格式的网页。

现在我的 PHP 页面只有以下代码:

<?php 
 echo file_get_contents("http://thegamesdb.net/api/GetGamesList.php?name=dog");    
?>

我找到了一个使用 Javascript 将 XML 转换为 JSON 的 JSFiddle:

https://jsfiddle.net/neowot/7hfyunbc/2/

...但我不确定如何使它与我的目的兼容。

任何帮助将不胜感激。谢谢。

【问题讨论】:

标签: javascript php jquery json xml


【解决方案1】:

这应该可行。答案取自PHP convert XML to JSON,稍作修改

$xml_string = file_get_contents("http://thegamesdb.net/api/GetGamesList.php?name=dog");
$xml = simplexml_load_string($xml_string);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-26
    • 2015-06-07
    • 1970-01-01
    • 1970-01-01
    • 2018-12-08
    • 2014-03-10
    • 2018-03-29
    • 2020-02-07
    相关资源
    最近更新 更多