我收到了这样的字符串:
id=123&nid=28&ntype=content&text=This%20is%20a%20note
我需要将此数据更改为 JSON。PHP中是否有任何内置函数或一些自定义函数?
试试这样...
$get_string = "id=123&nid=28&ntype=content&text=This%20is%20a%20note";
parse_str($get_string, $get_array);
echo json_encode($get_array);
你会得到这样的输出......
{"id":"123","nid":"28","ntype":"content","text":"This is a note"}
$tmp = parse_str($string);
echo json_encode($tmp);