[英]remove backslash from json - WP REST API
I am extending Wordpress Rest API.我正在扩展 Wordpress Rest API。 While building the APIs I see backslash even after adding json flags to remove them.在构建 API 时,即使在添加 json 标志以删除它们之后,我也会看到反斜杠。 What I am doing is below我正在做的是下面
stripslashes(json_encode(['success'=> true], JSON_FORCE_OBJECT | JSON_HEX_APOS));
Output Output
"{\"success\":false}"
Is there something I am missing above?上面有什么我遗漏的吗? I'm using PHP 7+我正在使用 PHP 7+
Do you actually need the flags JSON_FORCE_OBJECT
and JSON_HEX_APOS
?你真的需要标志JSON_FORCE_OBJECT
和JSON_HEX_APOS
吗? I mean if you just do我的意思是,如果你这样做
$json = json_encode(['success'=> true]);
echo $json;
it prints out valid json.它打印出有效的 json。
Even with your flags if you just output the json it runs completely fine without \
.即使有你的标志,如果你只是 output json 它运行完全没有\
。
>>> echo json_encode(['success' => true]);
{"success":true}⏎
>>> echo json_encode(['success' => true], JSON_FORCE_OBJECT);
{"success":true}⏎
>>> echo json_encode(['success' => true], JSON_FORCE_OBJECT | JSON_HEX_APOS);
{"success":true}⏎
So I suspect something in your output script that adds these \
.所以我怀疑你的 output 脚本中添加了这些\
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.