首頁 >後端開發 >php教程 >php解析json数据的问题

php解析json数据的问题

WBOY
WBOY原創
2016-06-23 14:28:13923瀏覽

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