secret
Created

Using JSON APIs In Notes

  • Download Gist
JSONDemo.java
Java
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
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;
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.