Rumah > pembangunan bahagian belakang > tutorial php > PHP的JSON解析问题

PHP的JSON解析问题

WBOY
Lepaskan: 2016-06-23 13:01:49
asal
946 orang telah melayarinya

{"type":"success","code":0,"message":null,"data":{"box_list":[{"boxId":"cfce938f2c7c11e69d5700000a00191c","boxNum":"nantong_test1","boxName":"我的保险柜","boxIp":"","boxMac":"","powerStatus":"0","networkStatus":"0","doorStatus":"2","shakeInfo":"1","deviceStatus":"1","boxStatus":"1","verifyStatus":"","lockPwd":"ABCD07033132333435363F030D","boxVersion":0,"channelId":"nantong_test1","boxControlPwd":"874d05d4bdd9077a7aefa0dc8c8cbd1f","adminUserId":"62f199be303b11e684c000000a00191c","boxPhone":"","defaultSkin":"0","netWorkName":"","agentId":"","createTime":null,"warninhCount":0,"batteryLevel":null,"temp":null},{"boxId":"73b1a2932c7211e69d5700000a00191c","boxNum":"lvlei6","boxName":"我的保险柜","boxIp":"","boxMac":"","powerStatus":"0","networkStatus":"0","doorStatus":"2","shakeInfo":"1","deviceStatus":"1","boxStatus":"1","verifyStatus":"","lockPwd":"ABCD07033132333435363F030D","boxVersion":30,"channelId":"lvlei6","boxControlPwd":"874d05d4bdd9077a7aefa0dc8c8cbd1f","adminUserId":"31f674062c8311e69d5700000a00191c","boxPhone":"","defaultSkin":"0","netWorkName":"","agentId":"","createTime":null,"warninhCount":0,"batteryLevel":null,"temp":null}],"user":{"id":"296d4ecc303d11e684c000000a00191c","userName":"kaka","loginName":"12@qq.com","loginPwd":"874d05d4bdd9077a7aefa0dc8c8cbd1f","userFinger1":"","userFinger2":"","userFinger3":"","type":"0","userPhone":"","userPhoto":"http://hissdata.blob.core.chinacloudapi.cn/userpicdata/296d4ecc303d11e684c000000a00191c_1465717285898.png","channelId":"","userListenDate":1465694992000,"boxNum":"","controlPwd":"","userNum":"","userAddress":"","userMail":"12@qq.com"}}}
Salin selepas log masuk


要获取box_list中的所有下标下的数据,
我的获取方式$c = $data['data']['box_list'][0]['boxId']; 但是不知为何获取到的是73b1a2932c7211e69d5700000a00191c 也就是box_list中下标为1的boxId。也仅仅只能获取这个 。
求大神!!!!!!!
求大神!!!!!!!
求大神!!!!!!!


回复讨论(解决方案)

没有问题的,你把解析后的数组打印出来核对一下

<?php$str = '{"type":"success","code":0,"message":null,"data":{"box_list":[	{"boxId":"cfce938f2c7c11e69d5700000a00191c","boxNum":"nantong_test1","boxName":"我的保险柜","boxIp":"","boxMac":"","powerStatus":"0","networkStatus":"0","doorStatus":"2","shakeInfo":"1","deviceStatus":"1","boxStatus":"1","verifyStatus":"","lockPwd":"ABCD07033132333435363F030D","boxVersion":0,"channelId":"nantong_test1","boxControlPwd":"874d05d4bdd9077a7aefa0dc8c8cbd1f","adminUserId":"62f199be303b11e684c000000a00191c","boxPhone":"","defaultSkin":"0","netWorkName":"","agentId":"","createTime":null,"warninhCount":0,"batteryLevel":null,"temp":null},	{"boxId":"73b1a2932c7211e69d5700000a00191c","boxNum":"lvlei6","boxName":"我的保险柜","boxIp":"","boxMac":"","powerStatus":"0","networkStatus":"0","doorStatus":"2","shakeInfo":"1","deviceStatus":"1","boxStatus":"1","verifyStatus":"","lockPwd":"ABCD07033132333435363F030D","boxVersion":30,"channelId":"lvlei6","boxControlPwd":"874d05d4bdd9077a7aefa0dc8c8cbd1f","adminUserId":"31f674062c8311e69d5700000a00191c","boxPhone":"","defaultSkin":"0","netWorkName":"","agentId":"","createTime":null,"warninhCount":0,"batteryLevel":null,"temp":null}],"user":{"id":"296d4ecc303d11e684c000000a00191c","userName":"kaka","loginName":"12@qq.com","loginPwd":"874d05d4bdd9077a7aefa0dc8c8cbd1f","userFinger1":"","userFinger2":"","userFinger3":"","type":"0","userPhone":"","userPhoto":"http://hissdata.blob.core.chinacloudapi.cn/userpicdata/296d4ecc303d11e684c000000a00191c_1465717285898.png","channelId":"","userListenDate":1465694992000,"boxNum":"","controlPwd":"","userNum":"","userAddress":"","userMail":"12@qq.com"}}}';$json = json_decode($str, true);echo $json['data']['box_list'][0]['boxId'], "\t", $json['data']['box_list'][1]['boxId'], "\n";
Salin selepas log masuk


cfce938f2c7c11e69d5700000a00191c	73b1a2932c7211e69d5700000a00191c
Salin selepas log masuk

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan