Java - lectura de archivo JSON orientada a objetos

 
Vista:
sin imagen de perfil

lectura de archivo JSON orientada a objetos

Publicado por George Alexander (1 intervención) el 22/02/2017 17:13:16
antes que nada, hola gracias por querer ayudar.

tengo mi programa en java que lee el archivo JSON de un url.
lo que necesito ahora es qu haga lo mismo pero poniéndole una interfaz sencilla (dos cuadros de texto y un botón.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import org.json.JSONException;
 
public class json
{
    private static String readUrl(String urlString) throws Exception {
    BufferedReader reader = null;
        try {
            URL url = new URL(urlString);
            reader = new BufferedReader(new InputStreamReader(url.openStream()));
            StringBuffer buffer = new StringBuffer();
            int read;
            char[] chars = new char[1024];
            while ((read = reader.read(chars)) != -1)
                buffer.append(chars, 0, read);
 
            return buffer.toString();
        } finally {
            if (reader != null)
                reader.close();
        }
  }
 
  public static void main(String[] args) throws Exception {
    try {
        JSONObject json = new JSONObject(readUrl("https://dl.dropboxusercontent.com/u/151704463/datos.json"));
        String name = (String) json.get("name");
        System.out.println("Name: " + name);
    } catch (JSONException e) {
        e.printStackTrace();
    }
  }
}


en el primer cuadro de texto tengo que escribir el url y al pulsar el botón debe salir todo el contenido del archivo en el segundo cuadro de texto.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder