rubygems
JSON
Recherche…
Introduction
Le json gem for Ruby permet l'analyse et la création de JSON.
Syntaxe
- JSON.parse (json_document_string) => renvoie un Hash du document JSON
- JSON.generate (ruby_hash) => renvoie un document JSON sous la forme d'une chaîne
Paramètres
| Paramètre | Détails |
|---|---|
| json_document_string | Un document JSON sous la forme d'une chaîne |
| ruby_hash | Tout objet Hash |
Hash to JSON
require 'json'
data = {"test" => 123}
puts JSON.generate(data)
JSON à Hash
require 'json'
document = "{\"test\":123}"
puts JSON.parse(document)
JSON alternatif à Hash
require 'json'
data = JSON '{"test":23}' # => {"test"=>23}
ou
require 'json'
data = JSON['{"test":23}'] # => {"test"=>23}
Hash alternatif à JSON
require 'json'
document = JSON 'test' => 23 # => "{\"test\":23}"
ou
require 'json'
document = JSON['test' => 23] # => "{\"test\":23}"
Modified text is an extract of the original Stack Overflow Documentation
Sous licence CC BY-SA 3.0
Non affilié à Stack Overflow