如何从外部网站提取XML文件并编码为JSON?我想能够检查XML文件中的某个值是true还是false,但我只会用JSON来做这件事,找不到任何关于如何使用XML来实现的资料。以下是我使用JSON API进行的操作:
$stringData = "<a href=\"http://www.twitch.tv/coldrewbie\"</a>coL.drewbie<br>\n";
$json_file = file_get_contents("http://api.justin.tv/api/stream/list.json?channel=coldrewbie");
$json_array = json_decode($json_file, true);
if ($json_array[0]['name'] == 'live_user_coldrewbie') {
fwrite($fh, $stringData);
}
唯一的问题是,我想要提取的另一个网站使用XML文档作为其API,而不是具有JSON选项。这是我的代码,但我认为它不正确,尽管可能有一定接近:
$xml = simplexml_load_file("http://api.own3d.tv/liveCheck.php?live_id=173952");
$json_file = json_encode($xml);
$json_array = json_decode($json, true);
if ($json_array[0]['isLive'] == 'true'){
echo "yup";
}
任何帮助都将非常棒!