我需要从包含多个json对象的文件中提取Object id total_time
{"alternative_names":[["",""]],"route_name":["",""],"status_message":"Found route between points","route_geometry":"qo{`o@wpslhBmFZwEpBgDzDeBlFWdGv@`G`CzEyBfIyEtEoNtEuMpAuHkAsCgC[mB{AgCuA{@uCa@}Cl@yBtB}@lDVhEcAtDmCdBcDx@iDDeDk@uBeBeB_CcGcXyFi^{Dg\\wBkP_Fs^wBiS_Ce[_D}UwAcKiBqIgI_TeLaUcMmP_IsHqf@_WyJeE}F`MkDjIiTth@y|@loBq^vy@mu@fw@cUxOco@r^gb@zRoOjPsBfMq@rMjBdPnEpKlEnH`J~Dvn@la@nd@pT|f@lLv_@pRzLbHnb@fUxc@lMnaC~zAncBxnA`kB|bB`|CbmCl]rY`xCzkCjwBzoBjxGl_G|fNhcMf~E~mE~pFt}EjbBlzAhvInyHfqDb~CblA`w@poAzt@z}@bb@diD~dBxtEjgCfjDljBpuAfw@bpGngDhqF~yC~g@la@v~@ni@rbAjg@jP`JlC`FNdDGdDu@j@eAhBa@lCLdCaCjI_BtCy@vA_DvF}qAf}Bof@l{@{CnFoKdR}mA`xBgM|TkJxPmLlSsf@|}@gf@`x@kOzXmEfGmSx^kf@tw@mDtL}k@r~@ykCjjEau@niAee@bu@uUl\\}DpFzCrCr|@dt@|NbLroBx_BdZlV|DbD`pBr~Anq@xm@r|@ls@|y@dq@}O`XuM`QcDhEoBgBeCCu[xXmBH","route_summary":{"end_point":"","start_point":"","total_time":824,"total_distance":15391},"found_alternative":true,"alternative_summaries":[{"end_point":"","start_point":"","total_time":886,"total_distance":14967}],"via_points":[[25.196808,55.273754],[25.139168,55.187702]],"status":0,"via_indices":[0,144],"hint_data":{"locations":["TdMLAP____8AAAAADwAAAA8AAAA9AAAAbAAAAOtwBgAAAAAACXmAARxpSwMEAAEB","4Q4AAGKyBgAAAAAACQAAAAAAAAAhAQAAAAAAAGUYAAAAAAAA4Zd_AfgYSgMGAAEB"],"checksum":326195011},"alternative_geometries":["qo{`o@wpslhBmFZwEpBgDzDeBlFWdGv@`G`CzEyBfIyEtEoNtEuMpAuHkAsCgC[mB{AgCuA{@uCa@}Cl@yBtB}@lDVhEcAtDmCdBcDx@iDDeDk@uBeBeB_CcGcXyFi^{Dg\\wBkP_Fs^wBiS_Ce[_D}UwAcKiBqIgI_TeLaUcMmP_IsHqf@_WyJeE}F`MkDjIiTth@y|@loBq^vy@ec@vfAyeAfcCok@vtA}Wtx@uS|d@skAvfCgExJgJpTqH|O}`@n~@wSve@qEhKkYdp@gB~DuUrk@_JdRsAhDmJlVqd@rcAuM|Zeg@zkAiKzUgIbS}B~EtDvBhr@`a@dQ~J|rBpmAj_CfyAlAzD^lDgHnOyQlg@w[l|@}Q~d@eBB}Af@mAdAw@bBWpBJrBn@hBaAjGif@ptAk^rmAoVxy@cHjPmC`H`E|Bp[xRpc@`ZfLvIzLlIreG~cEjrArz@rmAl|@lbDrzBjWlQ|xA~bAho@pc@d_@jWng@j^hNzJvGnEnPjLlAx@lgAhv@bGvCjkBvoAbjDr}BvfAx{@t\\rSfoDviC~zAjgAfOxIvAbAjwCtsBv|@|m@bD|BvL`Id_Dt|BtLlIxsAx_AfE~Crn@hc@rKvIh_BniApe@z\\xIpGtoBpxAtEdDrQrMzjChlB`~@lo@nwF`pE|jBl|AzFzE|DfDvDrCjKfJr`@n\\pLzK`nBzzAdO~LhaFxaEzCdCnLpKbp@ti@nIjHdRzMjo@tg@~MvKpwCtdClw@bm@z[bWfr@vk@zCrCr|@dt@|NbLroBx_BdZlV|DbD`pBr~Anq@xm@r|@ls@|y@dq@}O`XuM`QcDhEoBgBeCCu[xXmBH"],"alternative_indices":[0,183]}
{"hint_data":{"locations":["AXQDAP____8AAAAABwAAABEAAAAYAAAAIwIAAERwAgAAAAAADgyCAef7TAMCAAEB","bOsDAP____8AAAAAAwAAAAcAAADFAQAAFAAAAEJwAgAAAAAANQeCAdzdTAMFAAEB"],"checksum":326195011},"route_name":["",""],"via_indices":[0,15],"via_points":[[25.299982,55.376873],[25.29874,55.369179]],"found_alternative":false,"route_summary":{"end_point":"","start_point":"","total_time":101,"total_distance":871},"route_geometry":"{_ego@m}|rhBpBaBvHuC`EuArEUtEtAlDvEnD`MlDvMli@hsEfFzn@QlTgNhwCs@fKwBjF","status_message":"Found route between points","status":0}
我正在使用这个脚本,
<?php
$data = file_get_contents('sample.json');
$data = json_decode($data);
$totalTime = $data->route_summary->total_time;
var_dump($totalTime);
?>
但它给了我一个NULL输出。任何帮助,将不胜感激?
答案 0 :(得分:0)
可以通过
检索该值 $totalTime = $data['route_summary']['total_time'];
如果您传递给$data
的json格式正确。
答案 1 :(得分:0)
正如你所提到的,有两个json对象,然后我建议每行读取一次文件。然后,对于每一行,您可以解码json或转储它。希望有所帮助。
$lines = file('json.data');
foreach ($lines as $line_num => $line) {
// you are looking for first object
$data = json_decode($line);
$totalTime = $data->route_summary->total_time;
var_dump($totalTime);
break;
}