-1

我想保留目标字段的原始值并使用 json_decode 将以下字符串用作对象:

{
    "translatorID": "f4a5876a-3e53-40e2-9032-d99a30d7a6fc",
    "label": "ACL",
    "creator": "Nathan Schneider",
    "target": "^https?://(www[.])?aclweb\\.org/anthology-new/[^#]+",
    "minVersion": "1.0.7",
    "maxVersion": "",
    "priority": 100,
    "browserSupport": "gcs",
    "inRepository": true,
    "translatorType": 4,
    "lastUpdated": "2012-01-01 01:42:16"
}
4

2 回答 2

1

在解析之前你可以做的json_decode是:

$string = str_replace('\\', '\\\\\\\\', $string);
var_dump(json_decode($string, true));

这一定是 json 解析器中的错误。
该方法不是很干净,但至少您得到了结果。

于 2012-06-19T11:31:44.053 回答
1

你试过把斜线去掉吗?

这对我有用:

$string = '{
    "translatorID": "f4a5876a-3e53-40e2-9032-d99a30d7a6fc",
    "label": "ACL",
    "creator": "Nathan Schneider",
    "target": "^https?://(www[.])?aclweb\.org/anthology-new/[^#]+",
    "minVersion": "1.0.7",
    "maxVersion": "",
    "priority": 100,
    "browserSupport": "gcs",
    "inRepository": true,
    "translatorType": 4,
    "lastUpdated": "2012-01-01 01:42:16"
}';

var_dump( json_decode(stripslashes ($string)));
于 2012-06-19T11:52:45.247 回答