【发布时间】:2016-08-26 20:42:40
【问题描述】:
我正在尝试使用带有 JSON 编码和 JSON 解码的 PHP 来编辑一些 JSON 文件。
JSON 文件中有一些明显使用“/”的 URL。
当我使用 JSON_decode 并打印文本时,我得到如下信息:
url = http://www.example.com/something/hello_1.0;
然后我运行这个脚本:
$new['versions'] = array();
$new['versions'][$version] = current( $decode['versions'] );
foreach( $decode['versions'] as $sVersion => $aVersion ) {
$new['versions'][$sVersion] = $aVersion;
}
$decode['versions']= $new['versions'];
$encode = json_encode($decode,JSON_PRETTY_PRINT);
添加一个新版本,但是结果是:
url = http:\/\/www.example.com\/something\/hello_1.1;
url = http:\/\/www.example.com\/something\/hello_1.0;
当我打印 json_decode 数组时,它仍然有正确的“/”。
有什么想法吗?
【问题讨论】:
-
那又怎样?这里有问题吗?这只是逃避特殊角色的一种方式。
-
是的。问题是 JSON 应该如下所示: url = example.com/something/hello_1.0;否则它不会工作
-
什么不起作用?要使用 url,你必须解码你的 JSON 字符串,然后你得到未转义的 url,对吧?