rubygems
JSON
Ricerca…
introduzione
La gemma json per Ruby consente l'analisi e la creazione di JSON.
Sintassi
- JSON.parse (json_document_string) => restituisce un hash del documento JSON
- JSON.generate (ruby_hash) => restituisce un documento JSON sotto forma di stringa
Parametri
| Parametro | Dettagli |
|---|---|
| json_document_string | Un documento JSON sotto forma di stringa |
| ruby_hash | Qualsiasi oggetto Hash |
Hash to JSON
require 'json'
data = {"test" => 123}
puts JSON.generate(data)
JSON a Hash
require 'json'
document = "{\"test\":123}"
puts JSON.parse(document)
JSON alternativo a Hash
require 'json'
data = JSON '{"test":23}' # => {"test"=>23}
o
require 'json'
data = JSON['{"test":23}'] # => {"test"=>23}
Alternare Hash a JSON
require 'json'
document = JSON 'test' => 23 # => "{\"test\":23}"
o
require 'json'
document = JSON['test' => 23] # => "{\"test\":23}"
Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow