2016-12-14 12 views
0

私はPHPを使用しています 私はjson配列から特定のパラメータを取得する方法を知りたいです。だからここjson内の特定のパラメータを取得

は私のコードです:

$deviceList = $getdata->GetAll(); 
$json = json_decode($deviceList,true); 
$json = (object)$json; 
echo $json->imei; 

しかし、私はIMEIという名前のパラメータから任意のレコードを取得できませんでした。ここで

はJSONデータである:

{"id":"166","cellno":"639993370553","serialno":"0315212013915037","brand":"MeiTrack","model":"TC68S","imei":"867144020128490","description":"Personal Tracker","macaddress":"isjdioasjdioasn389257u238952","haulerid":"6","hauler":"Ronald","company_name":"Trial"},{"id":"165","cellno":"639993374250","serialno":"1234546789","brand":"MeiTrack","model":"MVT380","imei":"867965023790997","description":"32we4qweq","macaddress":"12343253","haulerid":"6","hauler":"Ronald","company_name":"Trial"},{"id":"164","cellno":"639433483172","serialno":"12345","brand":"O+","model":"O+ FAB GO","imei":"860799024505881","description":"Mobile","macaddress":"44:91:db:b8:16:78","haulerid":"5","hauler":"IOT Test","company_name":"Test Company2"},{"id":"163","cellno":"639499333494","serialno":"43854320246","brand":"MEITRACK","model":"MVT-380","imei":"867965023803394","description":"TEST","macaddress":"f82t7g8","haulerid":"5","hauler":"IOT Test","company_name":"Test Company2"},{"id":"162","cellno":"639499933495","serialno":"43854720788","brand":"MEITRACK","model":"MVT-380","imei":"867965026574638","description":"TEST","macaddress":"f82t7g8","haulerid":"5","hauler":"IOT Test","company_name":"Test Company2"},{"id":"161","cellno":"639278921057","serialno":"42241020","brand":"meitrack","model":"t1","imei":"13777002439873","description":"test","macaddress":"f82t7g8","haulerid":"1","hauler":"Hauler #1","company_name":"IOT Technology Inc."},{"id":"160","cellno":"639499933495","serialno":"123456","brand":"meitrack","model":"t1","imei":"13949003229021","description":"test","macaddress":"f82t7g8","haulerid":"1","hauler":"Hauler #1","company_name":"IOT Technology Inc."},{"id":"159","cellno":"639771188829","serialno":"64327864237894","brand":"Test","model":"Test","imei":"74238974238744","description":"test","macaddress":"f82t7g8","haulerid":"1","hauler":"Hauler #1","company_name":"IOT Technology Inc."},{"id":"158","cellno":"639157181128","serialno":"234234234234","brand":"Test","model":"Test","imei":"423423423423423","description":"Test","macaddress":"23df23f32f32","haulerid":"1","hauler":"Hauler #1","company_name":"IOT Technology Inc."},{"id":"157","cellno":"639218109920","serialno":"67767867","brand":"Test","model":"Test","imei":"5763566763276867","description":"Test","macaddress":"678FT7HV79GJ","haulerid":"3","hauler":"IOT Hauler","company_name":"Test Company2"},{"id":"154","cellno":"639495904194","serialno":"89630315240272466798","brand":"V4S","model":"V4S","imei":"865747022735013","description":"Colpal - new APK","macaddress":"b8:98:f7:c0:b3:a8","haulerid":"3","hauler":"IOT Hauler","company_name":"Test Company2"},{"id":"146","cellno":"639495904213","serialno":"89630315240272466954","brand":"Gionee","model":"V4S","imei":"865747022747802","description":"Colpal - new APK","macaddress":"b8:98:f7:c1:22:2f","haulerid":"3","hauler":"IOT Hauler","company_name":"Test Company2"},{"id":"145","cellno":"639981600078","serialno":"356707070404363","brand":"SAMSUNG","model":"SM-J105B","imei":"356707070404363","description":"UCM DEVICE","macaddress":"2C:AE:2B:5D:85:08","haulerid":"3","hauler":"IOT Hauler","company_name":"Test Company2"},{"id":"144","cellno":"639495904526","serialno":"89630315240272469354","brand":"V4S","model":"V4S","imei":"865747022700819","description":"MYA device (already changed the APK & URL)","macaddress":"b8:98:f7:bc:91:40","haulerid":"3","hauler":"IOT Hauler","company_name":"Test Company2"},{"id":"143","cellno":"639495904527","serialno":"89630315240272469362","brand":"GIONEE","model":"V4S","imei":"865747022762850","description":"Mya Device (Already updated APK & URL)","macaddress":"b8:98:f7:c0:7c:b0","haulerid":"3","hauler":"IOT Hauler","company_name":"Test Company2"},{"id":"139","cellno":"639495904175","serialno":"865747022780076","brand":"Gionee","model":"V4S","imei":"865747022780076","description":"Colpal","macaddress":"b8:98:f7:c0:2a:1a","haulerid":"3","hauler":"IOT Hauler","company_name":"Test Company2"},{"id":"137","cellno":"639214185416","serialno":"89630315225170455191","brand":"MyPhonemy81","model":"MyPhone_my81","imei":"359530070027704","description":"FMM Device","macaddress":"64:21:40:92:db:16","haulerid":"3","hauler":"IOT Hauler","company_name":"Test Company2"}] 

誰も私を助けることができますか?おかげさまで

+0

あなたがオブジェクトをしたい場合は、 'json_decode()' – RiggsFolly

+0

こんにちはオフ 'true'にパラメータを残します!すでにjsonデコードで真を削除しました。まだimeiを得ることができません –

答えて

0

あなたはオブジェクトの配列を示すjsonデータ構造を持っているので、それを処理したり、それを扱う必要があります。

$deviceList = $getdata->GetAll(); 
$json = json_decode($deviceList); 
foreach ($json as $obj) { 
    echo $obj->id . ' = ' . $obj->imei . '<br>'; 
} 

出力=

166 = 867144020128490 
165 = 867965023790997 
164 = 860799024505881 
163 = 867965023803394 
162 = 867965026574638 
161 = 13777002439873 
160 = 13949003229021 
159 = 74238974238744 
158 = 423423423423423 
157 = 5763566763276867 
154 = 865747022735013 
146 = 865747022747802 
145 = 356707070404363 
144 = 865747022700819 
143 = 865747022762850 
139 = 865747022780076 
137 = 359530070027704 
+0

ありがとう!!できます –

関連する問題