【发布时间】:2016-04-26 20:30:08
【问题描述】:
我正在尝试解析 post 请求返回的 JSON。我有以下代码:
response = RestClient.post "http://localhost:4567", request.body.read,:content_type => :json, :accept => :json
result = JSON.parse('#{response.body}')
它给了我以下错误:
JSON::ParserError - 757: unexpected token at '#{response.body}':
我已检查 response.body 返回正确的 JSON。如果我复制 JSON 的内容并将其粘贴到 JSON.parse 中,它会完美运行。但是,当我使用该变量时,它不起作用。
【问题讨论】:
-
你的问题是什么?
-
如何修复它以使解析工作?
-
你能展示一下
response.body的样子吗? -
@Atri 太长了,不适合放在这里。 { "age_result": [ { "column_id": [ "B01001003", "B01001027" ], "name": "5 岁以下", "number": [ 6774.0, 6416.0 ] }, { "column_id": [ "B01001004 ", "B01001028" ], "name": "5 到 9 年", "number": [ 5981.0, 6470.0 ] }, { "column_id": [ "B01001005", "B01001029" ] } 这是其中的一部分。
-
@JackLi 检查我的回答是否有帮助。