我有一个JSON响应,我需要在PHP中解析。这是原始的JSON:
{
"status": 200,
"status_message": "Route Successfull",
"data": [
[
["Karachi Company", "33.690166", "73.030357", "1-C"],
["Peshawar Mor", "33.684509", "73.047585", "1-C"],
["Federal Government College", "33.671909", "73.056038", "1-C"],
["I\/9 Police Station", "33.660728", "73.064430", "1-C"],
["Pindora Chungi", "33.652046", "73.064301", "1-C"],
["Double Road", "33.655663", "73.070930", "110"], 14
],
[
["Karachi Company", "33.690166", "73.030357", "115"],
["Bohar Masjid", "33.691372", "73.040985", "115"],
["Peshawar Mor", "33.684509", "73.047585", "115"],
["H-9 Education", "33.674938", "73.053757", "115"],
["H-9 College", "33.671967", "73.056007", "115"],
["Dalda Mills", "33.663872", "73.049942", "115"],
["I-9 Chowk", "33.656727", "73.055077", "115"],
["I-9 Market", "33.652618", "73.053719", "115"],
["CDA Colony", "33.641186", "73.043297", "115"],
["Katarian Pull", "33.646591", "73.053673", "110"],
["Pindora Chungi", "33.652046", "73.064301", "110"],
["Double Road", "33.655663", "73.070930", "110"], 32
],
[
["Karachi Company", "33.690166", "73.030357", "120"],
["FSD", "33.697506", "73.035721", "120"],
["Tipu Market", "33.700459", "73.041435", "120"],
["PIMS", "33.706490", "73.055450", "120"],
["Khyber Plaza", "33.708477", "73.056900", "120"],
["G-7\/2 Service Road", "33.703407", "73.058914", "120"],
["Sitara Market", "33.706654", "73.067314", "120"],
["Iqbal Hall", "33.709240", "73.074821", "120"],
["G-6\/2", "33.717533", "73.082520", "120"],
["Melody", "33.714916", "73.084656", "120"],
["Lal Masjid", "33.712467", "73.086685", "120"],
["Abpara", "33.708942", "73.089142", "120"],
["MNA Hostel", "33.726662", "73.090408", "120"],
["National Convention Center", "33.712711", "73.103676", "120"],
["Rawal Lake", "33.721302", "73.134445", "120"],
["Kashmir Chowk", "33.708317", "73.105339", "110"],
["Masjid Stop", "33.705292", "73.106873", "110"],
["Golf Club", "33.702656", "73.108376", "110"],
["Rawal Dam", "33.689449", "73.110977", "110"],
["Margalla Town", "33.678829", "73.104057", "110"],
["Faizabad", "33.663212", "73.084801", "110"],
["Double Road", "33.655663", "73.070930", "110"], 39
]
]
}
我试过
$result = json_decode($response);
$res = (array)$result[0]->data;
print_r($res);
但似乎只显示一个空数组。我原以为它是映射到data
键的数组。我应该怎么做才能获得这些数组?
答案 0 :(得分:0)
使用JavaScript
您的JSON是javascript object,data
获得. (DOT)
密钥值。
答案:1
var json = {}; // json data
var data=json.data; // now you can get any inner array with index.
var innerData=data[0];
var array=innerData[0]; //["Karachi Company", "33.690166", "73.030357", "1-C"]
console.log(array[0]); //Karachi Company
答案:2
function printJSON(json){
var data=json.data;
for(var i=0;i<data.length;i++){
var innerData=data[i];
for(var j=0;j<innerData.length;j++){
console.log(innerData[j]);
}
}
}