Advertisement
gonzalob

Untitled

Jun 23rd, 2022
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. package json;
  2.  
  3. import org.json.JSONArray;
  4. import org.json.JSONException;
  5. import org.json.JSONObject;
  6.  
  7. public class Main {
  8.  
  9.     public static void main(String[] args)
  10.     {
  11.         String fuente = JsonUtiles.leer("prueba");
  12.        
  13.         try
  14.         {
  15.             JSONObject jo = new JSONObject(fuente);
  16.             boolean success = jo.getBoolean("success");
  17.             int code = jo.getInt("code");
  18.             String nombre = jo.getString("nombre");
  19.            
  20.             JSONObject data = jo.getJSONObject("data");
  21.             JSONObject message = jo.getJSONObject("message");
  22.            
  23.             JSONObject error = message.getJSONObject("error");
  24.            
  25.             String mensaje = error.getString("mensaje");
  26.            
  27.             System.out.println(mensaje);
  28.            
  29.             String text = message.getString("text");
  30.            
  31.             System.out.println(text);
  32.            
  33.             int status = data.getInt("status");
  34.            
  35.             System.out.println(status);
  36.            
  37.             JSONArray array = jo.getJSONArray("servicios");
  38.            
  39.             for (int i=0;i<array.length();i++)
  40.             {
  41.                 JSONObject jsonObject = array.getJSONObject(i);
  42.                
  43.                 System.out.println(jsonObject.getString("service_text"));
  44.             }
  45.            
  46.             JSONArray etiquetas = jo.getJSONArray("etiquetas");
  47.            
  48.             for (int i=0;i<etiquetas.length();i++)
  49.             {
  50.                 String etiqueta = etiquetas.getString(i);
  51.                 System.out.println(etiqueta);
  52.             }
  53.            
  54.             //String text = jo.getString("text");
  55.            
  56.         }
  57.         catch (JSONException e) {
  58.             // TODO Auto-generated catch block
  59.             e.printStackTrace();
  60.         }
  61.        
  62.     }
  63.  
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement