[英]decoding json object inside object inside object
我正在嘗試使用json_decode()
解碼json文件,第二個參數為true
,它是從file_get_contents()
獲得的json字符串之后的。 像下面。
json_decode(file_get_contents($dir), true);
我已經確保文件中的目錄正確,並存儲在$dir
的json文件中。
{
"must": {
"title": {
"tag": "<!--section title-->",
"content": null,
"with-content": true
},
"class": {
"tag": "<!--section class-->",
"content": null,
"with-content": true
}
}
但是當我嘗試使用以下腳本獲取json文件時。
if(is_file_ready($dir)) {
$set = json_decode(file_get_contents($dir), true);
echo file_get_contents($dir);
if(isset($set['must'])) {
foreach($set['must'] as $node) {
echo $node['tag'];
}
}
它僅顯示第一個echo
如下所示, echo $node['tag']
顯示任何內容。
{“必須”:{“標題”:{“標簽”:“”,“內容”:null,“有內容”:true},“類別”:{“標簽”:“”,“內容”:null ,“ with-content”:true}}}
當我將echo $node['tag']
更改為print_r($node['tag'])
它顯示如下。
數組([tag] => [content] => [with-content] => 1)Array([tag] => [content] => [with-content] => 1)
我的問題是,為什么tag
返回null
而內容也返回? 是<!-- -->
讀為與html
相同的json
的注釋嗎? 還是我做錯了什么?
感謝您的任何更正。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.