php 将 POST 数组转换为 json 格式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8238502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
convert POST array to json format
提问by rails_noob
How can I convert php's POST variable to json format?
如何将 php 的 POST 变量转换为 json 格式?
回答by Code Magician
If this is entirely in php, and you simply want to convert the data in $_POST
to JSON, you can do so like this:
如果这完全是在 php 中,而您只是想将数据转换$_POST
为 JSON,您可以这样做:
$json = json_encode($_POST);
Using php's built-in function json_encode
(doc)
使用 php 的内置函数json_encode
( doc)
If this is not what you want to do, please be more specific with your question.
如果这不是您想要做的,请更具体地说明您的问题。
回答by Peter
json_encode($_POST);