testtongji.php 代码返回数据整理最后想要的结果
问题描述
testtongji.php 代码如下
<?php error_reporting(0);
$url = 'https://www.zzxxxx.xx/api/wetds/stats/';
$options = array(
'http' => array(
'header' => "Content-Type: application/json",
'header' => "Authorization: Token 633b4deb1cd517a01851a3335811b9ae8e1d6d6d",
'method' => 'GET',
'content' => http_build_query
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo ($result);
打开testtongji.php 返回数据如下
{"bandwidth_used":393073846353,"bandwidth_remaining":680667977647.0,"bandwidth_limit":1073741824000.0,"bandwidth_projected":1496203172977,"last_request_at":"2021-01-13T01:59:38.381732-08:00","requests_total":239278,"requests_successful":238115,"requests_failed":1163,"request_countries":{"US":238334,"NL":848,"RS":96},"requests_error_reasons":{"target_read_deadline":1142,"target_connect_timeout":12,"client_read_timeout":2,"client_read_eof":7},"request_failure_status_codes":{}}
echo ($result);整理如下
需要把以上返回的数据整理为以下内容 bandwidth_used":393073846353,"bandwidth_remaining":680667977647.0 计算出393073846353字节 =多少GB 680667977647.0字节==多少GB 像下面这样展示出,其他的数据都不要
已用流量: XXXX GB
剩余流量: XXXX GB
问题解答
回答1:接口数据返回给前端, 用js map方法处理就好了
相关文章:
1. 运行python程序时出现“应用程序发生异常”的内存错误?2. 我在导入模板资源时遇到无法显示的问题,请老师解答下3. macos - 无法source activate python274. java - butterknife怎么绑定多个view5. html5 - 前端面试碰到了一个缓存数据的问题,来论坛上请教一下6. css - 移动端 盒子内加overflow-y:scroll后 字体会变大7. PHPExcel表格导入数据库怎么导入8. javascript - react如何获取offsetX?9. html - 网页的a标签到底要不要写上域名?10. css3 让图片变成灰色(filter),但针对IE11浏览器无效

网公网安备