【问题标题】:Display json api data in html [closed]在html中显示json api数据[关闭]
【发布时间】:2019-01-26 18:40:25
【问题描述】:

我有一个 json API 密钥,我正在尝试获取 XXXX-102 帐户的“余额”值,但我做不到,您能帮帮我吗? 我想在 html 页面上显示它

这是我拥有的 API 密钥:https://www.dropbox.com/s/eqohltkxjawadsy/Screenshot%202019-01-26%2019.37.29.png?dl=0

链接 API:https://www.example.com/it/user/ApiWhsGetSubList?email=mymail@gmail.com&apikey=XXXX

【问题讨论】:

  • 不太明白,你是要求一个完整的javascript和html代码来做吗?

标签: php html json api


【解决方案1】:

您的结果中没有“平衡”键。可能是您正在寻找的“信用”吗?

$apiResult = json_decode($yourJsonString);
($apiResult['status'] !== 'ok') && 
  trigger_error('Unexpected API Result');

empty(($account = array_filter($apiResult['result'], function($item) {
  return $item['account'] === 'XXXX-102';
}))) && trigger_error('Account not found.');

echo $account[0]['credit'];

【讨论】:

  • 非常感谢!
【解决方案2】:

查看json_decode

然后你就可以像普通的 PHP 数组一样访问它了。像这样;

$php_array = json_decode( $YOUR_JSON_API_KEY );
echo $php_array['balance'];

【讨论】:

    【解决方案3】:
    $data = json_decode($json_data); 
    print_r($data->result[0]->billing);
    
    foreach ($data->result as $item) {
        echo $item->billing; 
    }
    

    您可以通过此 foreach 循环访问所有帐单详细信息。

    【讨论】:

      猜你喜欢
      • 2021-02-20
      • 2016-06-30
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 2010-10-27
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      相关资源
      最近更新 更多