我想保留目标字段的原始值并使用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"
}
答案 0 :(得分:1)
使用json_decode
解析之前,您可以执行的操作是:
$string = str_replace('\\', '\\\\\\\\', $string);
var_dump(json_decode($string, true));
这必须是json解析器中的错误 该方法不是很干净,但至少你得到的结果。
答案 1 :(得分: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)));