【问题标题】:get_content_file from a JSON file从 JSON 文件中获取内容文件
【发布时间】:2014-03-21 09:37:04
【问题描述】:

我需要获取一个json文件的内容。

我用:

$message_path = 'path/to/message.json';
$data = file_get_contents("$message_path");

echo $data;

这里是message.json:

{
  "message": "hello ${last_name} ${first_name}\nblabla",
  "date": null,
  "state": "DRAFT",
  "externalUrl": null,
  "landingPageType": "custom",
  "landingPageTitle": null,
  "sourceAddress": null,
  "flash": false,
  "type": 'STANDARD',
  "scheduledType": "now"
}

这里是回声:

"{n  "message": "hello ${last_name} ${first_name}nblabla",n  "date": null,n  "state": "DRAFT",n  "externalUrl": null,n  "landingPageType": "custom",n  "landingPageTitle": null,n  "sourceAddress": null,n  "flash": false,n  "type": 'STANDARD',n  "scheduledType": "now"n}

为什么所有这些 'n' 字符?这个怎么去掉?

【问题讨论】:

    标签: php json file-get-contents


    【解决方案1】:

    这些ns 是换行符。只需parse $data to JSON 就可以了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-24
      • 2021-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-10
      • 2013-10-29
      • 1970-01-01
      相关资源
      最近更新 更多