【问题标题】:PHP PUT data to Json in RESTful APIPHP PUT 数据到 Json 中的 RESTful API
【发布时间】:2012-08-21 06:31:40
【问题描述】:

我收到了这样的字符串:

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

我需要将此数据更改为 JSON。 PHP中是否有任何内置函数或一些自定义函数?

【问题讨论】:

标签: php json api rest


【解决方案1】:

试试这样...

$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"}

【讨论】:

    【解决方案2】:
    $tmp = parse_str($string);
    echo json_encode($tmp);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-17
      • 2017-12-01
      • 2012-10-08
      • 2013-05-25
      • 1970-01-01
      • 2012-02-26
      相关资源
      最近更新 更多