Created
January 22, 2019 02:54
-
-
Save parzibyte/8e12593e206d91e9ea96e1530b074283 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 | |
entero = 1 | |
flotante = 15.2 | |
cadena = "parzibyte.me" | |
booleano = true | |
nulo = nil | |
arreglo = [1, 2, 3] | |
hash = {"clave" => "valor"} | |
puts entero.to_json | |
# 1 | |
puts flotante.to_json | |
# 15.2 | |
puts cadena.to_json | |
# "parzibyte.me" | |
puts booleano.to_json | |
# true | |
puts nulo.to_json | |
# null | |
puts arreglo.to_json | |
# [1,2,3] | |
puts hash.to_json | |
# {"clave":"valor"} | |
# Ahora un objeto más grande y complejo | |
mascota = { | |
"nombre" => "Maggie", | |
"edad" => 3, | |
"peso" => 5.2, | |
"amigos" => [ | |
{ | |
"nombre" => "Capuchina", | |
"edad" => 2 | |
}, | |
{ | |
"nombre" => "Guayaba", | |
"edad" => 1 | |
} | |
] | |
} | |
codificada = mascota.to_json | |
puts codificada | |
# {"nombre":"Maggie","edad":3,"peso":5.2,"amigos":[{"nombre":"Capuchina","edad":2},{"nombre":"Guayaba","edad":1}]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment