String to JsonObject

Discussion in 'Plugin Development' started by MCCoding, Nov 30, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    MCCoding

    I'm wanting to convert my string into a JsonObject but it seems that the object is returning null for some weird reason, here is the method I'm using now the json string returning the correct string and is a valid JsonString but as soon as I try convert it into the JsonObject it then becomes null.

    Code:java
    1.  
    2. import org.bukkit.craftbukkit.libs.com.google.gson.Gson;
    3. import org.bukkit.craftbukkit.libs.com.google.gson.JsonObject;
    4.  
    5. public static Channel createChannel(String channelname) {
    6. try {
    7. String json = API.readJsonFromUrl("[url]http://gdata.youtube.com/feeds/api/users/[/url]" + channelname + "?alt=json");
    8.  
    9. System.out.println("JSOPN " + json);
    10. if (json != null) {
    11. Gson gson = new Gson();
    12. JsonObject jb = gson.fromJson(json, JsonObject.class);
    13. if (jb != null) {
    14. System.out.println("Gson " + jb.toString());
    15. Channel channel = new Channel(jb);
    16. return channel;
    17. }
    18. }
    19. } catch (Exception e) {
    20. e.printStackTrace();
    21. }
    22.  
    23. return null;
    24. }
     
  2. Offline

    themuteoneS

    Is there any stack trace? You output to console several times. Can we see some of that output?

    Sidenote: Reading through the javadocs for these is usually fairly helpful since you can see the exact behaviour of every method.
     
Thread Status:
Not open for further replies.

Share This Page