I need to push some JSON data to my website which I would like to read in PHP. What type of file should I make this? A PHP file with the JSON inside of a variable? I understand how to make a text file with JSON encoded data in it, but how do I get this into PHP? Should I use a PHP include with the JSON-encoded data in it assigned to a variable? Or should I read the file from PHP and put the contents into a variable?
2条回答 默认 最新
- douba4275 2010-08-29 17:05关注
Save your json string as plain text, then you can use:
$file = yourfile $data = file_get_contents($file); $parsed = json_decode($data); // compacted: $parsed = json_decode(file_get_contents($file));
See
file_get_contents()
andjson_decode()
.The advantage of doing this (versus storing it in a PHP file then including it) is that now any program or language that understands JSON can read the file.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报