使用jquery AJAX和PHP创建特殊的JSON文件

使用jquery AJAX和PHP创建特殊的JSON文件,php,jquery,arrays,json,object,Php,Jquery,Arrays,Json,Object,我有以下json文件格式: { "Deutsch":"German", "Englisch":"English", "Französisch":"French", "Spanisch":"Spanish", } 现在,我想阅读此文件并使用PHP将其打印在我网站上的文本区域中: $file = '../js/json/en.json'; $json = file_get_contents($file); $obj = array(); $obj = json_decode($jso

我有以下json文件格式:

{       
"Deutsch":"German",
"Englisch":"English",
"Französisch":"French",
"Spanisch":"Spanish",
}
现在,我想阅读此文件并使用PHP将其打印在我网站上的文本区域中:

$file = '../js/json/en.json';
$json = file_get_contents($file);
$obj = array();
$obj = json_decode($json, true);

$output .= "<table style='width:100%'>";
$output .= "<tr>";
$output .= "<th>German</th>";
$output .= "<th>English</th>";
$output .= "<th>Your Language</th>";
foreach($obj as $key => $val) {
    $output .= "<tr><td><textarea class='german' style='width:100%;' readonly>".$key."</textarea></td><td><textarea class='english' style='width:100%' readonly>".$val."</textarea></td><td><textarea class='new_lang' style='width:100%'></textarea></p></td></tr>";
}
$output .= "</table>";
以及trans.php文件:

$myArray = $_POST['myData'];
$posts = array();
foreach($myArray as $key => $value) {
    //array_push($posts, $key .":". $value);
    $posts[] = array("$key" => "$value");
}
var_dump( $myArray);

$fp = fopen('js/json/tfr.json', 'w');
fwrite($fp, json_encode($posts));
fclose($fp);
有没有人有关于如何正确操作以获得与上面相同格式的提示

提前谢谢。

您可以更改

$posts[] = array("$key" => "$value");


现在输出看起来怎么样
$posts[] = array("$key" => "$value");
$posts[$key] = $value;