我一直在使用PHP中的json_decode()函数读取JSON中的大量数据时遇到了非常困难的时期。基本上,我需要阅读基本数据以显示航班日期的始发地和目的地。
这应该是这样的:
20 solutions found.
Solution# 1 Sale Price: BRL2919.54
Slice 0
TA 916 GRU 2015-06-16T06:15-03:00 LIM 2015-06-16T09:20-05:00
AV 962 LIM 2015-06-16T10:04-05:00 MIA 2015-06-16T16:48-04:00
这是JSON代码:http://pastebin.com/dH16RriT
当我尝试对其进行转换并读取时,它带有NULL数据。
$data = json_decode($results, true); // $results is a variable with
the JSON content from the URL above
echo $data['tripOption']['saleTotal']; // just an example
是的,您应该使用
print_r($a['trips']['tripOption'][0]['saleTotal'])
如果要读取该数组中的数据,可以执行以下操作:
$data = json_decode($s,true);
foreach ($data['trips']['tripOption'] as $item){
print_r($item['saleTotal'] . "\n");
};
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句