From the Ruby document, I can see that the Load (source, proc = nil, options = {}) Load a ruby data structure from a JSON source and return it to either a source or a string -It can be an object, respond like an IO-like object, or an object reading method. If proc was given, then with any nested ruby object in depth it will be said in the first order as a logic. Alternatively, the default option can also change the default option. This method is part of the implementation of the load / dump interface of Marshall and YAML. Also aliased as: Restored Pars (source, opts = {}) Parsing JSON document source in a ruby data structure and return it. load method assumes a proc as arg while < Code> does not parse Is there any other difference? Say, when I have the string of JSON, then what method should I change it to a Ruby object?
JSON # parse A JSON string parsing in Ruby hash Does.
JSON.parse ('{"name": "some names"}') # = & gt; {"Name" = & gt; "Some names"}
JSON # load takes either a string or IO (file etc.) and converts ruby hash / arrays
JSON.load File.new ("names.json") # = & gt; Inside the file, JSON and Ruby objects read the results. In fact, it changes any object that responds to
#read >>. code> method for example:
initialize class ADR @ a = '{"name": "some names"}' end def Is read @a and json.load (ANUE) # = & gt; {"Name" = & gt; "Some names"}
No comments:
Post a Comment