[英]trouble to update or edit the json file using php
index.json
myjsoncallback([{"ProductID":1,"ProductName":"Chai","UnitPrice":18,"UnitsInStock":39,"Discontinued":false}])
郵遞區號:
$string = file_get_contents("../index.json");
$string = utf8_encode($string);
$json_data = json_decode($string, true);
echo $json_data;
$i=count($json_data);
$json_data[$i] = array('ProductID'=>$fileName,'ProductName'=>$name,'ptext'=>$message,'Discontinued'=>false);
$fp = fopen('../index.json', 'a');
fwrite($fp, json_encode($json_data));
fclose($fp);
我想使用jsonpcallback將數據寫入jsone文件。
如果文件包含JSONP數據,則不能使用json_decode()
。 如果要使用PHP處理JSON數據,則必須刪除回調形式JSONP並僅對JSON對象進行編碼/解碼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.