我有一个从html发送的json字符串...
[{"user_id":"test_123"},{"id":"wallName","value":"","type":"text"},{"id":"wallLength","value":"","type":"text"}]
我要检索"user_id":"test_123"
,然后从中创建一个名为test_123的文件夹,甚至可能是一个名为test_123的匹配文件。我想我需要将json文件转换为数组,获取user_id
值并将其转换回字符串?这是否有意义,或者我是否为此感到复杂?我是php新手,所以很可能是这种情况。
这是我的PHP代码...
<?php
$json=$_POST[json];
$decodedText=html_entity_decode($json);
$myArray = json_decode($json, true);
if (json_decode($json) != null){
$file=fopen('user_data.json','w+');
fwrite($file, $json);
fclose($file);
}else{
echo "empty";
}
?>
当我尝试访问$myArray
时不起作用。
您可以使用获取user_id $myArray[0]['user_id']
;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句