Json Parsing

Discussion in 'BungeeCord Plugin Development' started by Skaiz, May 21, 2017.

  1. Hi,

    I'm having trouble which is that I don't know what I'm exactly doing wrong here, it should work fine..

    Code (Text):
    try {
                    @SuppressWarnings("deprecation")
                    URL url = new URL("https://api.mojang.com/user/profiles/" + uuid.replaceAll("-", "") + "/names");
                   
                   
                   
       
                    URLConnection connection = url.openConnection();
                    BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
                    String text = in.readLine();
         
                    JsonParser jp = new JsonParser();
                    String parsed = jp.parse(text).getAsString();
                   
                   
                    s(s, "&eKnown as:&f " + parsed);  
                    in.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
     
  2. .. and what is the problem? Any errors?
     
  3. It doesn't actually parse anything, it either doesn't even send the message.
     
  4. Add some debug lines, like System.out.println(text)
     
  5. Use Gson included in the spigot api since 1.8 (?)
     
  6. Both works. JsonSimple is for simple json stuff while gson, while can be used for the simple stuff, is for the more advanced :)

    Anyways. Add some debugging and tag me. I work with json all the time.
     
  7. The category we are in currently is BungeeCord, not Spigot :p, but thanks anyway!
     
  8. Also included at Bungee, but yeah...
     
  9. Is it? I haven't heard of that..?
     
  10. Try to import some Gson objects
     
  11. It's bundled in the Bukkit API and in BungeeCord chat.