Ruby Rest 客户端发送转义的 JSON



我正在使用Sinatra和rest-client发送JSON有效负载并对其进行处理(请求需要密钥对签名)。

但是,看起来 rest-client 正在发送转义的 JSON。

我的休息客户端日志:

RestClient.post uriHere, "{"eventID":1}", "Accept"=>"application/json", "Accept-Encoding"=>"gzip, deflate", "Authorization"=>"Bearer tokenHere", "Content-Hash"=>"sha1 signatureHere", "Content-Length"=>"xyz", "Content-Type"=>"application/json", "Date"=>"Thu, 29 Jan 2015 22:26:47 GMT"

我无法真正验证端点是否正在读取转义字符,但如果它像那样发送它们,显然它不是有效的 JSON。我尝试过 .gsub,但它没有删除多余的斜杠。

思潮?

我几乎可以肯定日志中是这样的,即实际有效载荷是有效的 JSON。

这意味着它是文本,应该通过 JSON.parse 传递:

new_hash = JSON.parse(the_payload)

然后new_hash['eventID']1

最新更新