0

I'm trying to do a json to hash, but I give this

JSON.parse({"tag":"DownloadRequest","hash":"c8\u0006ùM]ÁaSßwÃ9\u0007Ãò\u0013Â4lÊ·|j\\ëç","part_number":0})
TypeError: exception class/object expected

How I fix it?

1 Answer 1

2

What you're currently passing to JSON#parse isn't a valid Ruby Hash object; it's just raw JSON. JSON#parse expects a string containing valid JSON instead. Everything works fine if you wrap your JSON inside a string like so:

require 'json'
str = '{"tag":"DownloadRequest","hash":"c8\u0006ùM]ÁaSßwÃ9\u0007Ãò\u0013Â4lÊ·|j\\ëç","part_number":0}'
JSON.parse str

It now returns:

{"tag"=>"DownloadRequest", "hash"=>"c8\u0006ùM]ÁaSßwÃ9\aÃò\u0013Â4lÊ·|jëç", "part_number"=>0}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.