Java Json Get getValueFromJson(JsonObject currentJsonObject, String key)

Here you can find the source of getValueFromJson(JsonObject currentJsonObject, String key)

Description

get Value From Json

License

Apache License

Declaration

public static String getValueFromJson(JsonObject currentJsonObject, String key) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.json.JsonObject;

public class Main {
    public static String getValueFromJson(JsonObject currentJsonObject, String key) {
        String result = "";
        if (currentJsonObject.containsKey(key)) {
            switch (currentJsonObject.get(key).getValueType()) {
            case STRING:
                result = currentJsonObject.getString(key);
                break;
            case NUMBER:
                result = String.valueOf(currentJsonObject.getInt(key));
                break;
            case NULL:
                result = "";
                break;

            }/*from  w w  w.  j av a  2  s.  c om*/
        }
        return result;
    }
}

Related

  1. getKeyAsString(JsonObject obj, String key, String defaultValue)
  2. getLongProperty(JsonObject object, String property)
  3. getPrettyJsonWriterFactory()
  4. getSitesFromDb(String replicationSitesInDB)
  5. getString(JsonObject jso, String name)