Skip to content

Instantly share code, notes, and snippets.

@henriqueutsch
Created May 6, 2015 02:01
Show Gist options
  • Save henriqueutsch/fd0e1b55680411f70e7f to your computer and use it in GitHub Desktop.
Save henriqueutsch/fd0e1b55680411f70e7f to your computer and use it in GitHub Desktop.
require 'json'
my_hash = JSON.parse('{"hello": "goodbye"}')
puts my_hash.class => Hash
puts my_hash["hello"] => goodbye
p teste = '{"result":[]}{"result":[{"alternative":[{"transcript":"abrir chrome","confidence":0.92921507},{"transcript":"abrir o chrome"}],"final":true}],"result_index":0}'
p teste.encoding
puts teste
puts resposta = JSON.parse(teste)
puts resposta.class => string
puts resposta = JSON.parse([ teste ].to_json).first
puts resposta.class => string
puts resposta = JSON.parse(teste.to_json).first
puts resposta.class => string
/usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/json/common.rb:155:in `parse': 757: unexpected token at '{"result":[{"alternative":[{"transcript":"abrir chrome","confidence":0.92921507},{"transcript":"abrir o chrome"}],"final":true}],"result_index":0}' (JSON::ParserError)
from /usr/local/Cellar/ruby/2.1.5/lib/ruby/2.1.0/json/common.rb:155:in `parse'
@cristianoliveira
Copy link

Falta uma virgula para separar os objetos do JSON.

[{"result"=>[]},
{"result"=>[{"alternative"=>[{"transcript"=>"abrir chrome", "confidence"=>0.92921507}, {"transcript"=>"abrir o chrome"}], "final"=>true}], "result_index"=>0}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment