我想要反转JSON文件(使用php,python,java或其他解决方案:))
来自:
{
"name 1" : "value 1",
"name 2" : "value 2"
}
致:
{
"value 1" : "name 1",
"value 2" : "name 2"
}
想法? :)
谢谢!
答案 0 :(得分:3)
试试这个:
<?php
$str=<<<EOT
{
"name 1" : "value 1",
"name 2" : "value 2"
}
EOT;
echo json_encode(array_flip(json_decode($str,true)));
?>
输出:{"value 1":"name 1","value 2":"name 2"}