我从json获得了一个数组,但我不知道如何获取booktitle和url。
如何读取数组中的这些项?
$data = file_get_contents('C:\Users\rsanchro\Desktop\ftp brasil4-9-2015\moderna_plus-historia\MPCH-C05-P1-1.0.1-ZIP-PT\resource.json');
$datos = json_decode($data, true);
print_r($datos);die;
Results:
Array
(
[topBarColor] => #000000
[bookId] => 2aef55bf3a9dec377b4f16a8048c7f84
[bookTitle] => História
[unitId] => MPCH-C05-P1
[unitTitle] => 108-127-MPCH-C05-P1-M
[unitResources] => Array
(
[0] => Array
(
[type] => 03
[url] => resources/mphis_c06av_escultura_ontem.mp4
[urlToShowInsideUnit] => #/compId/id0a33b2a0471e0f444bc0a88b5bb55714
[title] => A escultura ontem e hoje
[page] => 123
)
)
)
最佳答案
用这个
print_r(utf8_decode($datos['bookTitle']));
if(is_array($datos['unitResources']) && count($datos['unitResources']) > 0){
foreach($datos['unitResources'] as $key => $value){
print_r($value['url']);
}
}
关于php - 我如何在php中获取json,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32821118/