-
-
Save ryanjbaxter/554a2fd80015b3f199a1 to your computer and use it in GitHub Desktop.
Using JSON APIs In Notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JSONDemo { | |
private String myJsonString; | |
/** | |
* Constructor | |
* @param myJsonString a string representation of JSON | |
*/ | |
public JSONDemo(String myJsonString) { | |
this.myJsonString = myJsonString; | |
} | |
/* | |
* Gets a Java object which you can use to get values from the JSON. | |
* @return a Java object which you can use to get values from the JSON | |
*/ | |
public JsonJavaObject getJson() { | |
try { | |
//Use the extended instance so we can get back a JsonJavaObject from JsonParser | |
JsonFactory jsonFactory = JsonJavaFactory.instanceEx; | |
Object obj = JsonParser.fromJson(jsonFactory, myJsonString); | |
if(obj instanceof JsonJavaObject){ | |
JsonJavaObject jsonObject = (JsonJavaObject)obj; | |
return jsonObject | |
} | |
} catch (JsonException e) { | |
e.printStackTrace(); | |
} catch (TokenMgrError e){ | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment