Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中解析自定义json_Php_Json - Fatal编程技术网

如何在php中解析自定义json

如何在php中解析自定义json,php,json,Php,Json,我有一个json值,如下所示: { "A":{"id":"1","checked":false}, "B":{"id":"2","checked":true}, "C":{"id":"3","checked":true} } 我只需要id和检查值。我不知道A,B,C中的值是多少 $jsonIterator = new RecursiveIteratorIterator( new RecursiveArrayIterator(js

我有一个json值,如下所示:

 {
    "A":{"id":"1","checked":false},
    "B":{"id":"2","checked":true},
    "C":{"id":"3","checked":true}
}
我只需要
id
检查值。我不知道
A
B
C
中的值是多少

        $jsonIterator = new RecursiveIteratorIterator(
            new RecursiveArrayIterator(json_decode($chboxs, TRUE)),
            RecursiveIteratorIterator::SELF_FIRST);

        foreach ($jsonIterator as $key => $val) {
            if(is_array($val)) {
               // echo "$key:\n";
            } else {
                //echo "$key => $val\n";
                if($val == true){
                    $val = 1 ;
                }else{
                    $val = 0 ;
                }
                $ch = array();
                $ch['isvisible'] = $val;

                $this->m_general->edit('coupon_properties' , $ch , array('id'=>$key));
            }
        }
它不好用

只需使用:

因此,这将为您提供:

Array (
  A => Array (
    id => 1,
    checked => false
  )
  B => ...
)
你可以像这样得到它:

$arr["A"]["id"];      // 1
$arr["B"]["checked"]; // true
因此,要进行迭代,可以使用:

foreach ($arr as $ar) {
  echo $ar["id"], $ar["checked"];
}

看看:
json\u decode()
+
array\u column()
我不知道a、B、C的值是多少。@S.M\u Emamian您想要的输出是什么?echo
$id
和echo
$value
@S.M_Emamian感谢您的编辑。如果行得通,你能接受我的回答吗?
foreach ($arr as $ar) {
  echo $ar["id"], $ar["checked"];
}