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. javascript - 打算寫一個c++的node圖像處理模塊,有沒有推薦的c++圖片處理庫?2. java - 同步/異步與阻塞/非阻塞之間的差異具體是什么?3. html5 - 前端面試碰到了一個緩存數據的問題,來論壇上請教一下4. macos - 無法source activate python275. css - 移動端 盒子內加overflow-y:scroll后 字體會變大6. java - butterknife怎么綁定多個view7. css3 讓圖片變成灰色(filter),但針對IE11瀏覽器無效8. angular.js - angularjs 怎么封裝 upload 上傳9. 運行python程序時出現“應用程序發生異常”的內存錯誤?10. android - Genymotion 模擬器可以做屏幕適配檢測嗎?

網公網安備