dongxin2734 2015-04-20 17:49
浏览 118

API返回String,需要数组

I am trying to work with the ResellersPanel API and I have managed to get this far with my code:

$result = file_get_contents("https://api.duoservers.com/?auth_username=store-name&auth_password=PasswordHere&section=datacenters&command=get_datacenters");
var_dump($result);

Now for whatever reason, they thought it would be a good idea to return everything as a string rather than json or an array.

I need to know how to convert every result into json or an array. The result of the above code is:

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 "

How would I convert a string to json? Thank you.

In the documentation it does state that they return an array. So why is it returning a string? I've tried contacting them and they told me to contact a web developer for help.

STILL NO SOLUTION.

  • 写回答

2条回答 默认 最新

  • dongxingqiu7943 2015-04-20 17:51
    关注

    You can you the explode() function.

    $result = file_get_contents("https://api.duoservers.com/?auth_username=store-name&auth_password=PasswordHere&section=datacenters&command=get_datacenters");
    
    $result = trim($result);
    $plans  = explode(" ", $result);
    echo $plans[5]; // steadfast
    echo $plans[6]; // shared
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度