将POST数组转换为json格式

时间:2023-01-15 09:13:26

How can I convert php's POST variable to json format?

如何将php的POST变量转换为json格式?

2 个解决方案

#1


32  

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.

如果这不是您想要做的,请更具体地说明您的问题。

#2


2  

json_encode($_POST);

#1


32  

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.

如果这不是您想要做的,请更具体地说明您的问题。

#2


2  

json_encode($_POST);