rubygems
JSON
Sök…
Introduktion
json pärlan för Ruby gör det möjligt att analysera och skapa JSON.
Syntax
- JSON.parse (json_document_string) => returnerar en Hash för JSON-dokumentet
- JSON.generate (ruby_hash) => returnerar ett JSON-dokument i form av en sträng
parametrar
| Parameter | detaljer |
|---|---|
| json_document_string | Ett JSON-dokument i form av en sträng |
| ruby_hash | Varje Hash-objekt |
Hash till JSON
require 'json'
data = {"test" => 123}
puts JSON.generate(data)
JSON till Hash
require 'json'
document = "{\"test\":123}"
puts JSON.parse(document)
Alternativ JSON mot Hash
require 'json'
data = JSON '{"test":23}' # => {"test"=>23}
eller
require 'json'
data = JSON['{"test":23}'] # => {"test"=>23}
Alternativ Hash till JSON
require 'json'
document = JSON 'test' => 23 # => "{\"test\":23}"
eller
require 'json'
document = JSON['test' => 23] # => "{\"test\":23}"
Modified text is an extract of the original Stack Overflow Documentation
Licensierat under CC BY-SA 3.0
Inte anslutet till Stack Overflow