Example usage for javax.json JsonArray getString

List of usage examples for javax.json JsonArray getString

Introduction

In this page you can find the example usage for javax.json JsonArray getString.

Prototype

String getString(int index, String defaultValue);

Source Link

Document

Returns the String value of JsonString at the specified position in this JSON array values.

Usage

From source file:com.buffalokiwi.aerodrome.jet.JetAPIResponse.java

/**
 * Check the response body for errors/*  w  w  w.  j  ava2s.  c  om*/
 * @param res JSON results
 * @throws JetException if there's an issue
 */
public static final void checkErrors(final JsonObject res, final IAPIResponse apiRes) throws JetException {
    if (res.containsKey("errors")) {
        final JsonArray errors = res.getJsonArray("errors");
        ArrayList<String> messages = new ArrayList<>();

        for (int i = 0; i < errors.size(); i++) {
            messages.add(errors.getString(i, ""));
        }

        throw new JetException(messages, null, apiRes);
    } else if (res.containsKey("error")) {
        throw new JetException(res.getString("error"), null, apiRes);
    }
}

From source file:com.buffalokiwi.aerodrome.jet.JetAPI.java

/**
 * Turn a jet api response into a list of tokens 
 * @param a Json array /*from w w w.  ja  v a  2s .  co  m*/
 * @param includePath Toggle including the entire uri or only the rightmost
 * part.
 * @return tokens 
 */
protected List<String> jsonArrayToTokenList(final JsonArray a, final boolean includePath) {
    final List<String> out = new ArrayList<>();

    if (a != null) {
        for (int i = 0; i < a.size(); i++) {
            out.add(processTokenPath(a.getString(i, ""), includePath));
        }
    }

    return out;
}