我正在尝试使用ResellersPanel API,我已经设法用我的代码做到了这一点:
$result = file_get_contents("https://api.duoservers.com/?auth_username=store-name&auth_password=PasswordHere§ion=datacenters&command=get_datacenters");
var_dump($result);现在,无论出于什么原因,他们认为将所有内容作为字符串而不是json或数组返回将是一个好主意。
我需要知道如何将每个结果转换为json或数组。上面代码的结果是:
string(1468) " 0 0 56000 steadfast shared semidedicated dedicated vps vps_solusvm london shared semidedicated vps vps_solusvm australia sis_group shared semidedicated vps_solusvm telepoint shared semidedicated vps_solusvm ficolo shared semidedicated vps_solusvm 0.027 s 0.019 s 4605066977 "如何将字符串转换为json?谢谢。
在documentation中,它声明它们返回一个数组。那么为什么它要返回一个字符串呢?我试着联系他们,他们告诉我联系web开发人员寻求帮助。
仍然没有解决方案。
发布于 2015-04-21 01:51:27
您可以使用explode()函数。
$result = file_get_contents("https://api.duoservers.com/?auth_username=store-name&auth_password=PasswordHere§ion=datacenters&command=get_datacenters");
$result = trim($result);
$plans = explode(" ", $result);
echo $plans[5]; // steadfast
echo $plans[6]; // shared发布于 2015-04-21 01:55:33
$result = file_get_contents("https://api.duoservers.com/?auth_username=store-name&auth_password=PasswordHere§ion=datacenters&command=get_datacenters");
$jsonData = json_encode(explode(' ', $result));发布于 2021-05-10 11:05:25
你可以使用return_type=serialization,如果你使用的是PHP,它会在序列化的时候返回它。它是一个数组
https://stackoverflow.com/questions/29754916
复制相似问题