字符串中的反斜杠返回两个反斜杠
输入了此访问令牌值
864876322670016\u00257C4e1d481ecad9eb45b9386745.1-1026038548\u00257CshuA8v7lgo7-hRr2AjbUBd3shek,
我在表单上
但它返回时带有双反斜杠,如下所示864876322670016\\u00257C4e1d481ecad9eb45b9386745.1-1026038548\\u00257CshuA8v7lgo7-hRr2AjbUBd3shek
我将此值传递给 Facebook GraphAPI,这会返回错误。
如何获得 return 将双反斜杠替换为单反斜杠?或者有没有办法让双反斜杠不出现?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定它实际上是用双反斜杠返回的吗?内部带有反斜杠的字符串看起来像有双反斜杠,因为 Ruby 会转义它们:
但是如果它们是双反斜杠,你可以这样做:
Are you sure it's actually returned with double backslashes? Internally strings with backslashes will look like they have double backslashes because Ruby is escaping them:
But if they are double backslashes you can do something like this:
这只是它的显示方式,以转义形式。您的错误可能在其他地方。
这是对输出的常见误解,当您第一次看到它时会有点困惑,正如 Casper 所指出的那样。
来自这个问题/答案,该人的问题本质上是相同的:
还有一个关于这个感知问题的简短讨论在此博文中。
It's just the way it's being displayed, in escaped form. Your error is likely elsewhere.
This is a common misinterpretation of the output, and a little confusing when you first see it, as Casper has pointed out.
From this question/answer, where the person's issue was essentially the same:
There's also a short discussion of this perceived issue in this blog post.