Created
January 22, 2019 02:57
-
-
Save parzibyte/0c7f457832d4c6873828ca7ced083cb3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
Codificar y decodificar JSON (JavaScript Object Notation) | |
en el lenguaje de programación Ruby | |
@author parzibyte | |
=end | |
mascota = { | |
"nombre" => "Maggie", | |
"edad" => 3, | |
"peso" => 5.2, | |
"amigos" => [ | |
{ | |
"nombre" => "Capuchina", | |
"edad" => 2 | |
}, | |
{ | |
"nombre" => "Guayaba", | |
"edad" => 1 | |
} | |
] | |
} | |
codificada = mascota.to_json | |
# Para decodificar, usamos JSON.parse | |
decodificada = JSON.parse(codificada) | |
puts decodificada["nombre"] | |
# Maggie | |
puts JSON.parse('1.5') | |
# 1.5 | |
nulo = JSON.parse('null') | |
if nulo === nil | |
puts "Es nulo" | |
end | |
# Es nulo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment