PHP的JSON解析问题

WBOY
Libérer: 2016-06-23 13:01:49
original
921 Les gens l'ont consulté

{"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"}}}
Copier après la connexion


要获取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";
Copier après la connexion


cfce938f2c7c11e69d5700000a00191c	73b1a2932c7211e69d5700000a00191c
Copier après la connexion

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal