简体   繁体   English

在RESTful API中将PHP PUT数据发送到Json

[英]PHP PUT data to Json in RESTful API

I have received a string like this: 我收到了这样的字符串:

    id=123&nid=28&ntype=content&text=This%20is%20a%20note

I need to change this data to JSON. 我需要将此数据更改为JSON。 Is there any in-built function in PHP or some custom function? PHP中是否有任何内置函数或某些自定义函数?

Try like this... 这样尝试...

$get_string = "id=123&nid=28&ntype=content&text=This%20is%20a%20note";
parse_str($get_string, $get_array);
echo json_encode($get_array);

You will get output like this... 您将得到这样的输出...

{"id":"123","nid":"28","ntype":"content","text":"This is a note"}
$tmp = parse_str($string);
echo json_encode($tmp);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM