>백엔드 개발 >PHP 튜토리얼 >php解析json数据的问题

php解析json数据的问题

WBOY
WBOY원래의
2016-06-23 14:28:13925검색

json php

{
   "Response":{
       "Head":{
           "ChuFaZhan":{
               "CheZhanBianHao":"69eb262a-067b-4ad0-8b6e-c968358971e5",
               "CheZhanBianMa":"1777018410",
               "CheZhanMingCheng":"济南"
           },
           "DaoDaZhan":{
               "CheZhanBianHao":"3e8b13db-f1ad-459d-97c2-02838c92293c",
               "CheZhanBianMa":"1049301979",
               "CheZhanMingCheng":"乌鲁木齐"
           }
       },
       "Main":{
           "@Rows":"2",
           "Item":[
               {
                   "@Id":"1",
                   "CheCiBianHao":"508f7049-ad1f-493b-9955-5ed51dc7b1f1",
                   "CheCiBianMa":"1351577673",
                   "CheCiMingCheng":"L207",
                   "CheXingMingCheng":"普快",
                   "ShiFaZhan":"济南",
                   "ChuFaZhan":"济南",
                   "DaoDaZhan":"乌鲁木齐",
                   "ZhongDianZhan":"乌鲁木齐",
                   "FaShi":"05:00",
                   "DaoShi":"15:06",
                   "LiShi":"58:06",
                   "LiCheng":"0",
               },
               {
                   "@Id":"2",
                   "CheCiBianHao":"b9f3f9de-eb0e-47b5-8cbf-d0451cc2acca",
                   "CheCiBianMa":"1175193122",
                   "CheCiMingCheng":"1085",
                   "CheXingMingCheng":"普快",
                   "ShiFaZhan":"济南",
                   "ChuFaZhan":"济南",
                   "DaoDaZhan":"乌鲁木齐",
                   "ZhongDianZhan":"乌鲁木齐",
                   "FaShi":"09:20",
                   "DaoShi":"10:11",
                   "LiShi":"48:51",
                   "LiCheng":"0",
               }
           ]
       }
   }
}
这样一个json,请问怎么样能取到Head中ChuFaZhan中CheZhanMingCheng的值和Main中Item中ChuFaZhan的值,出发站这个值是循环输出的

回复讨论(解决方案)

$jsp = '{   "Response":{       "Head":{           "ChuFaZhan":{               "CheZhanBianHao":"69eb262a-067b-4ad0-8b6e-c968358971e5",               "CheZhanBianMa":"1777018410",               "CheZhanMingCheng":"济南"           },           "DaoDaZhan":{               "CheZhanBianHao":"3e8b13db-f1ad-459d-97c2-02838c92293c",               "CheZhanBianMa":"1049301979",               "CheZhanMingCheng":"乌鲁木齐"           }       },       "Main":{           "@Rows":"2",           "Item":[               {                   "@Id":"1",                   "CheCiBianHao":"508f7049-ad1f-493b-9955-5ed51dc7b1f1",                   "CheCiBianMa":"1351577673",                   "CheCiMingCheng":"L207",                   "CheXingMingCheng":"普快",                   "ShiFaZhan":"济南",                   "ChuFaZhan":"济南",                   "DaoDaZhan":"乌鲁木齐",                   "ZhongDianZhan":"乌鲁木齐",                   "FaShi":"05:00",                   "DaoShi":"15:06",                   "LiShi":"58:06",                   "LiCheng":"0"               },               {                   "@Id":"2",                   "CheCiBianHao":"b9f3f9de-eb0e-47b5-8cbf-d0451cc2acca",                   "CheCiBianMa":"1175193122",                   "CheCiMingCheng":"1085",                   "CheXingMingCheng":"普快",                   "ShiFaZhan":"济南",                   "ChuFaZhan":"济南",                   "DaoDaZhan":"乌鲁木齐",                   "ZhongDianZhan":"乌鲁木齐",                   "FaShi":"09:20",                   "DaoShi":"10:11",                   "LiShi":"48:51",                   "LiCheng":"0"               }           ]       }   }}';$jsp_arr = json_decode($jsp);var_dump($jsp_arr->Response->Head->ChuFaZhan->CheZhanMingCheng);var_dump($jsp_arr->Response->Main->Item[0]->ChuFaZhan);

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.