-
-
Save parzibyte/ac49afe25f74a9d1076df0e920cecbb1 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
// En tus imports coloca sin comentar: | |
// import org.json.JSONObject; | |
// Poner el JSON en un String para demostrar | |
String cadenaJson = "{\"nombre\":\"Maggie\",\"edad\":3}"; | |
// Crear un nuevo objeto JSON | |
JSONObject objetoJson = new JSONObject(cadenaJson); | |
// Y ahora podemos acceder a través de getTipoDeDato | |
int edad = objetoJson.getInt("edad"); | |
String nombre = objetoJson.getString("nombre"); | |
// Luego de eso podemos crear la clase y obtener los beneficios | |
// de la POO o usar los datos como nos plazca | |
Mascota mascota = new Mascota(nombre, edad); | |
// Podemos hacer lo que sea con el objeto | |
mascota.ladrar(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment