Java Json Get getIntArray(JsonObject object, String name)

Here you can find the source of getIntArray(JsonObject object, String name)

Description

get Int Array

License

Open Source License

Declaration

public static int[] getIntArray(JsonObject object, String name) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import javax.json.JsonArray;
import javax.json.JsonNumber;
import javax.json.JsonObject;

import javax.json.JsonValue;

public class Main {
    public static int[] getIntArray(JsonObject object, String name) {
        return toIntArray(getJsonArray(object, name));
    }//from  w w w  . ja v a 2  s .c o m

    public static int[] toIntArray(JsonArray jsonArray) {
        if (jsonArray == null)
            return new int[0];
        int[] ret = new int[jsonArray.size()];
        for (int i = 0; i < jsonArray.size(); i++) {
            ret[i] = ((JsonNumber) jsonArray.get(i)).intValue();
        }
        return ret;
    }

    public static JsonArray getJsonArray(JsonObject object, String name) {
        if (hasKey(object, name)) {
            return object.getJsonArray(name);
        }
        return null;
    }

    public static JsonArray getJsonArray(JsonArray object, int index) {
        if (object == null)
            return null;
        if (object.size() <= index)
            return null;
        JsonValue value = object.get(index);
        if ((value == null) || (value == JsonValue.NULL)) {
            return null;
        }
        return object.getJsonArray(index);
    }

    public static boolean hasKey(JsonObject object, String name) {
        JsonValue value = object.get(name);
        if ((value == null) || (value == JsonValue.NULL)) {
            return false;
        }
        return true;
    }
}

Related

  1. getBoolean(JsonObject json, String name)
  2. getBooleanValue(JsonValue value)
  3. getBuilderFactory()
  4. getInt(JsonObject json, String name)
  5. getIntegerArrayList(JsonArray array)
  6. getIntegerArrayListSansDoublons( JsonArray array)
  7. getJsonArray(JsonObject object, String name)
  8. getJsonIntArray(Iterable integers)