【发布时间】:2012-08-21 06:31:40
【问题描述】:
我收到了这样的字符串:
id=123&nid=28&ntype=content&text=This%20is%20a%20note
我需要将此数据更改为 JSON。 PHP中是否有任何内置函数或一些自定义函数?
【问题讨论】:
我收到了这样的字符串:
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);
【讨论】: