我得到的回应是
page_play_model_exponentModel__getNum({"code":1,"message":"","result":{"icode":"JXdywDcV0hA","totalVv":6}})
这不是典型的JSON响应。所以当我使用像
这样的activesupport时 decode_response = ActiveSupport::JSON.decode(response)
,它会报告
JSON::ParserError: 795: unexpected token at 'page_play_model_exponentModel__getN
um({"code":1,"message":"","result":{"icode":"JXdywDcV0hA","totalVv":6}})
'
我该如何正确解析?我想要totalVv
值,我可以让它变丑,
喜欢
totalVv = response.split("'totalVv':")[1].split("}")[0]
,但这很奇怪。
答案 0 :(得分:2)
它看起来像JSONP响应,但您可以使用正则表达式来提取JSON
response = 'page_play_model_exponentModel__getNum({"code":1,"message":"","result":{"icode":"JXdywDcV0hA","totalVv":6}})'
json = /(\{.*\})/.match().to_s