如何访问特定的JSON数据?

时间:2015-06-09 16:54:03

标签: php json

[["pdf-sample.pdf",["uploads\/28\/pdf-sample.pdf"],{"en":"PDF Sample"},"","28"],["pdf-sample2.pdf",["uploads\/29\/pdf-sample2.pdf"],{"en":"Second PDF sample"},"","29"]]

现在我知道如何访问uploads\28\pdf-sample.pdf部分 - 只需输入$value[1][0],但我需要获取该文件的说明,即PDF Sample - 我该如何访问该文件?

到目前为止我的代码:

$files = json_decode($p['file']);
foreach ($files as $value) {
   echo $value[1][0].'<br />';
}

1 个答案:

答案 0 :(得分:1)

您正在将其解码为对象,以便访问您需要执行的en

$files = json_decode('[["pdf-sample.pdf",["uploads\/28\/pdf-sample.pdf"],{"en":"PDF Sample"},"","28"],["pdf-sample2.pdf",["uploads\/29\/pdf-sample2.pdf"],{"en":"Second PDF sample"},"","29"]]');

    foreach ($files as $value) {
        echo $value[2]->en.'<br />';
    }