Ich bekomme diesen Fehler, wenn Sie versuchen, die Antwort von rest_client zu analysieren.JSON :: ParserError: 743: unerwartetes Token in ROR
JSON :: ParserError: 743: unerwartetes Token ‚{
require 'rest_client'
require 'json'
class Kele
attr_accessor :data
def initialize(u,p)
#@values = {email: u, password: p}
@values = '{"email": "[email protected]", "password": "password"}'
@headers = {:content_type => 'application/json'}
@data = self.post
end
def post
response = RestClient.post 'https://private-anon-8506c5665f-blocapi.apiary-mock.com/api/v1/sessions', @values, @headers
end
end
In Ruby irb,
r = b.post
=> <RestClient::Response 200 "{\n \"auth...">
JSON.parse(r.body)
=> JSON::ParserError: 743: unexpected token at '{
a = Kele.new(1,2)
=> #<Kele:0x000000042e2e18 @values="{\"email\": \"[email protected]\", \"password\": \"password\"}", @headers={:content_type=>"application/json"}, @data=<RestClient::Response 200 "{\n \"auth...">>
a.post.body
=> "{\n \"auth_token\":\"eyJ0eXAiOiJKV1QiLCJhhGciOiJIUzI1NiJ9.eyJhcGlfa2V5IjoiYTc2MDZkNTBhYjA3NDE4ZWE4ZmU5NzliY2YxNTM1ZjAiLCJ1c2VyX2lkIjoyMzAzMTExLCJuYW1lIjoiQmVuIE5lZWx5In0.3VXD-FxOoxaGXHu6vmL8g191bl5F_oKe9qj8Khmp9F0\",\n \"user\":\n {\n \"id\":2307245,\n \"email:\"[email protected]\",\n \"created_at\":\"2015-08-11T16:31:08.836-07:00\",\n \"updated_at\":\"2015-11-04T13:13:32.457-08:00\",\n \"facebook_id\":null,\n ...,\n \"gender\":null\n }\n}"
Ich habe versucht, diese HTTParty mit auch:
require 'HTTParty'
class Kele
include HTTParty
def initialize(email,password)
@options = {query: {email: email, password: password}}
end
def post
self.class.post('https://private-anon-8506c5665f-blocapi.apiary-mock.com/api/v1/sessions', @options)
end
end
I bekomme immer noch diesen Fehler:
JSON.parse(a.post.body)
=> JSON::ParserError: 743: unexpected token at '{
dank verwenden sollte, aber ich habe versucht, dass, und es führt den gleichen Fehler aus. Ich habe gerade versucht, HTTParty zu verwenden, und es gibt auch den gleichen Fehler aus. – Leogoesger