[英]how to add or insert record in json file
how can i add or insert record(in a form of array) in my json file using php or javascript? 我如何使用php或javascript在json文件中添加或插入记录(以数组形式)?
i've tried this one but no luck: 我已经尝试过了,但是没有运气:
$file = file_get_contents('Copy.json');
$tempArray = json_decode($file);
$arr = array('type' => 'Feature',
'id'=>$adsID,
'properties' => array(
'IMAGE'=>$ALogo,
'NAME'=>$name,
'TEL'=>$ATel,
'URL'=>$url,
'ADRESS1'=>$A_add,
'ADDRESS2'=>'add2',
'CITY'=>'Angeles City',
'ZIP'=>'2009'),
'geometry' => array(
'type' => 'Point',
'coordinates' => array ($ACoords1))
) ;// features
echo json_encode($arr);//$data[] = $_POST['data'];
array_push($tempArray, $arr);
$jsonData = json_encode($tempArray);
file_put_contents('Copy.json', $jsonData);
array merge $file = file_get_contents('Copy.json'); 数组合并$ file = file_get_contents('Copy.json'); $tempArray = json_decode($file); $ tempArray = json_decode($ file);
$arr = array('type' => 'Feature',
'id'=>$adsID,
'properties' => array(
'IMAGE'=>$ALogo,
'NAME'=>$name,
'TEL'=>$ATel,
'URL'=>$url,
'ADRESS1'=>$A_add,
'ADDRESS2'=>'add2',
'CITY'=>'Angeles City',
'ZIP'=>'2009'),
'geometry' => array(
'type' => 'Point',
'coordinates' => array ($ACoords1))
) ;// features
echo json_encode($arr);//$data[] = $_POST['data'];
$merge = array_merge($tempArray, $arr);
$jsonData = json_encode($merge);
file_put_contents('Copy.json', $jsonData);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.