我使用'gem json'并且需要从某个url加载JSON数据,例如:
"http://locallhost:3000/qwerty/give_json.json" 同
{"one":"Omg","two":125,"three":"Hu"}
Run Code Online (Sandbox Code Playgroud)
我有rails app
class QwertyController < ApplicationController
require 'json'
def get_json
source = "http://localhost:3000/qwerty/give_json.json"
@data = JSON.parse(JSON.load(source))
end
end
Run Code Online (Sandbox Code Playgroud)
我收到错误
JSON::ParserError in QwertyController#get_json
795: unexpected token at 'http://localhost:3000/qwerty/give_json.json'
Run Code Online (Sandbox Code Playgroud)
在字符串中:@data = JSON.parse(JSON.load(source))
有什么事?如何获取JSON数据并解析它?我试试@data ["one"] ......