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
如何在PHP中逐行获取一级JSON的键和值_Php_Json - Fatal编程技术网

如何在PHP中逐行获取一级JSON的键和值

如何在PHP中逐行获取一级JSON的键和值,php,json,Php,Json,我从Javascript接收到一个JSON数组作为$\u POST变量 我想得到JSON的所有变量及其值。我试图使用json_解码与foreach类似的bellow,但它没有工作。我的php代码是 <?php $string = $_POST['json']; var_dump(json_decode($string, true)); foreach($string as $key => $value) { echo $key . " : " . $value; } ?>

我从Javascript接收到一个JSON数组作为$\u POST变量

我想得到JSON的所有变量及其值。我试图使用json_解码与foreach类似的bellow,但它没有工作。我的php代码是

<?php

$string = $_POST['json'];
var_dump(json_decode($string, true));
foreach($string as $key => $value) {
  echo $key . " : " . $value;
}

?>
它以类似于bellow的数组形式返回请求(我没有粘贴所有结果)

我所期望的是

EXTAPP_ID: 9901
CATEGORY_ID:10
LANGUAGE_CODE:de
CATEGORY_LANG_DESC:DE AAA
请尝试以下方法:

$string = json_decode($_POST['json'], true);
foreach($string as $key => $value) {
  echo $key . " : " . $value;
}
试试这个:

$string = $_POST['json'];
$data = json_decode($string, true);
var_dump($data);
foreach($data as $key => $value) {
  echo $key . " : " . $value;
}

使用
$string=json\u Decode($\u POST['json'],true)解码字符串

您可以通过以下代码获得所需的结果

$string = $_POST['json'];
$string = json_decode($string, true);
foreach($string as $value) {
    foreach($value as $k=>$v) {
        echo $k . " : " . $v .'<br/>';
    }
    echo '<hr>';
}
$string=$\u POST['json'];
$string=json_decode($string,true);
foreach($string作为$value){
foreach($k=>v的值){
回声$k.:“$v.”
; } 回声“
”; }
您必须首先解码json:
$string=json\u decode($\u POST['json'],true)你说“它不起作用”是什么意思?它输出的是什么错误?它返回一个类似数组(6){[0]=>array(4){[“EXTAPP_ID”]=>string(4)“9901”[“CATEGORY_ID”]=>string(2)“10”[“LANGUAGE_CODE”]=>string(2)“tr”[“CATEGORY_langu DESC”]=>string(19)“tr XXX”}[1]=>array(4){[“EXTAPP ID”]=>string(4)“9901”[“CATEGORY_ID”]=>字符串(2)“10”[“语言代码”]=>字符串(2)“de”[“类别语言描述”]=>字符串(17)“TR YYY”}类别描述太长,我只是手动更改了它。所以这不是问题
$string = $_POST['json'];
$data = json_decode($string, true);
var_dump($data);
foreach($data as $key => $value) {
  echo $key . " : " . $value;
}
$string = $_POST['json'];
$string = json_decode($string, true);
foreach($string as $value) {
    foreach($value as $k=>$v) {
        echo $k . " : " . $v .'<br/>';
    }
    echo '<hr>';
}