Warframe JSON 文件

问题描述 投票:0回答:1

在线游戏 Warframe 通过 json 文件提供对游戏元素的安全访问(描述见 https://warframe.fandom.com/wiki/Public_Export 页面)。无法在 PHP 中转换为数组。 json文件被访问但没有转换为数组。

$basis = file_get_contents("http://content.warframe.com/PublicExport/Manifest/ExportWeapons_en.json!00_mrFPI-tnYdaXwZkA8dRNaA");
$wps = json_decode($basis,true);
print(is_array($wps));

为什么不是数组? 怎么会是数组呢?

php json
1个回答
0
投票

JSON 无效,您可以通过启用

JSON_THROW_ON_ERROR
标志看到:

$json = file_get_contents('http://content.warframe.com/PublicExport/Manifest/ExportWeapons_en.json!00_mrFPI-tnYdaXwZkA8dRNaA');
$wps = json_decode($json, true, 512, JSON_THROW_ON_ERROR);

输出:

Fatal error: Uncaught JsonException: Control character error, possibly incorrectly encoded

该文件包含一些不允许的原始 CR/LF 序列。您只需删除它们即可修复它:

$json = file_get_contents('http://content.warframe.com/PublicExport/Manifest/ExportWeapons_en.json!00_mrFPI-tnYdaXwZkA8dRNaA');
$json = str_replace("\r\n", '', $json);
$wps = json_decode($json, true, 512, JSON_THROW_ON_ERROR);
printf('%d weapons found', count($wps['ExportWeapons']));

输出:

774 weapons found
© www.soinside.com 2019 - 2024. All rights reserved.