Introduction
Hoepsch JSON is inspired by the org.json and FlexJSON Java libraries.
Currently the marshalling is under construction.
Hoepsch JSON is easy to use, consistent and tested.
Empty / null values are treated as null, trying to get a
non-existent key will return null as well.
See Quick Usage for a short overview of what Hoepsch JSON does, or see the API,
JavaDoc (to be done), test code or Cobertura
coverage report for more examples.
Quick Usage
Some simple usage how to get a value from
the parsed JSON source. Basically this means calling
JSONObject#get<Type>()
String source = "{ \"foo\": \"bar\" }";
JSONObject jsonObject = new JSONObject(source);
String foo = jsonObject.getString("foo");
// foo == "bar"
String baz = jsonObject.getString("baz");
// baz == null
/*
* Getting an object with a default value applies to:
* - null values
* - non exitent keys
*/
baz = jsonObject.getString("baz", "default value");
// baz == "default value"
/*
* org.json uses optString for this
*/
baz = jsonObject.optString("baz");
// or
baz = jsonObject.optString("baz", "default value");
Some simple usage how to create a new JSON
string from Java. Basically this means calling
JSONObject#add(key,
value)
JSONObject jsonObject = new JSONObject();
jsonObject.add("foo", "bar");
// foo == "bar"
// Add a boolean:
jsonObject.add("foo", false);
jsonObject.add("foo", Boolean.TRUE);
// Adding a key, value pair twice will overwrite the previous value.
Changelog
- 2010-02-23New site layout
A bit more hacking on testing Marshalling
Added some very rudimentary Unmarshalling
- 2010-02-20
0.5.0
First draft of Bean Marshalling