我收到了这样的字符串:
id=123&nid=28&ntype=content&text=This%20is%20a%20note
我需要将此数据更改为JSON。 在PHP或某些自定义函数中是否有任何内置函数?
答案 0 :(得分:3)
试试这个......
$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"}
答案 1 :(得分:2)
$tmp = parse_str($string);
echo json_encode($tmp);