The list of methods to do Json are organized into topic(s).
String
asString(JsonValue value) as String
if (JsonValue.ValueType.STRING.equals(value.getValueType())) {
return ((JsonString) value).getString();
return value.toString();
boolean
compare(JsonValue expected, JsonValue actual, boolean strict) compare
switch (expected.getValueType()) {
case OBJECT:
if (actual.getValueType() == ValueType.OBJECT) {
return jsonEquals((JsonObject) expected, (JsonObject) actual, strict);
break;
case ARRAY:
if (actual.getValueType() == ValueType.ARRAY) {
...
Object
convertJsonValue(Object jsonValue, Class desiredType) convert Json Value
if (jsonValue instanceof JsonNumber) {
JsonNumber number = (JsonNumber) jsonValue;
if (desiredType == null || desiredType == Long.class || desiredType == Long.TYPE) {
return number.longValue();
} else if (desiredType == Integer.class || desiredType == Integer.TYPE) {
return number.intValue();
} else if (desiredType == Double.class || desiredType == Double.TYPE) {
return number.doubleValue();
...
String
escape(String text) Escape a string.
if (text == null)
return null;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < text.length(); i++) {
char ch = text.charAt(i);
switch (ch) {
case '"':
sb.append("\\\"");
...
void
fill_dictionary(Map dictionary, JsonObject jsonObject) fildictionary
if (dictionary == null || jsonObject == null) {
return;
for (String key : jsonObject.keySet()) {
JsonValue valueObj = (JsonValue) jsonObject.get(key);
JsonValue.ValueType type = valueObj.getValueType();
if (type == JsonValue.ValueType.ARRAY) {
JsonArray arrayObj = jsonObject.getJsonArray(key);
...
void
fill_list(JsonObjectBuilder jsonObject, String key, List list) fillist
if (jsonObject == null || key == null) {
return;
JsonArrayBuilder arrayBuilder = jsonFactory.createArrayBuilder();
for (Object entry : list) {
if (entry instanceof Map) {
JsonObjectBuilder entryObj = jsonFactory.createObjectBuilder();
fill_map(entryObj, (Map<String, Object>) entry);
...
String
fromDictionary(Map dictionary) from Dictionary
if (dictionary == null) {
return null;
JsonObjectBuilder root = jsonFactory.createObjectBuilder();
fill_map(root, dictionary);
return root.build().toString();