本文目錄一覽:
php提取json數據
$dataJson = “數據”; // 提供數據
$data = json_decode($dataJson); // 數據按json解析成php數組
$minuteArr = $data[‘minute’]; // 從數組中獲取minute數據
此時$minuteArr中存放的就是你要的數據,但數組下標(鍵)是從0開始,如需要從1開始,則遍歷$minuteArr修改下標(鍵) 或 使用php數組函數進行快速重構。
註:你這問題是還沒入門的初學者問的問題,建議還是多看看書!…
PHP json數據寫入到json文件,讀取json文件
// 生成一個PHP數組
$data = array();
$data[‘name’] = ‘admin’;
$data[‘pwd’] = ‘123456’;
// 把PHP數組轉成JSON字元串
$json_string = json_encode($data);
// 寫入文件
file_put_contents(‘user.json’, $json_string);
// 從文件中讀取數據到PHP變數
$json_string = file_get_contents(‘user.json’);
// 把JSON字元串轉成PHP數組
$data = json_decode($json_string, true);
// 顯示出來看看
var_dump($data)
php如何讀取json的內容
如果json是以對象的方式存儲於變數$json中,則這樣引用: $json-openid
如果json是以關聯數組的方式存儲於變數$json中,則這樣引用: $json[‘openid’]
如果json是以字元串的方式存儲於變數$json中,則需要先轉換一下:
$a = json_decode($json);
print_r($a-openid);
或者
$a = json_decode($json,true);
print_r($a[‘openid’]);
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/295688.html