Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created February 11, 2019 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/ac49afe25f74a9d1076df0e920cecbb1 to your computer and use it in GitHub Desktop.
Save parzibyte/ac49afe25f74a9d1076df0e920cecbb1 to your computer and use it in GitHub Desktop.
// 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