rubygems
JSON
Zoeken…
Invoering
De json edelsteen voor Ruby zorgt voor het parseren en maken van JSON.
Syntaxis
- JSON.parse (json_document_string) => retourneert een Hash van het JSON-document
- JSON.generate (ruby_hash) => retourneert een JSON-document in de vorm van een string
parameters
| Parameter | Details |
|---|---|
| json_document_string | Een JSON-document in de vorm van een string |
| ruby_hash | Elk Hash-object |
Hash naar JSON
require 'json'
data = {"test" => 123}
puts JSON.generate(data)
JSON naar Hash
require 'json'
document = "{\"test\":123}"
puts JSON.parse(document)
Alternatieve JSON voor Hash
require 'json'
data = JSON '{"test":23}' # => {"test"=>23}
of
require 'json'
data = JSON['{"test":23}'] # => {"test"=>23}
Alternatief Hash voor JSON
require 'json'
document = JSON 'test' => 23 # => "{\"test\":23}"
of
require 'json'
document = JSON['test' => 23] # => "{\"test\":23}"
Modified text is an extract of the original Stack Overflow Documentation
Licentie onder CC BY-SA 3.0
Niet aangesloten bij Stack Overflow