Class JsonUtils


  • public class JsonUtils
    extends Object
    Helper methods for retrieving data from JSONObject
    • Constructor Summary

      Constructors 
      Constructor Description
      JsonUtils()  
    • Constructor Detail

      • JsonUtils

        public JsonUtils()
    • Method Detail

      • getStringValue

        public static String getStringValue​(org.json.JSONObject jsonObject,
                                            String property,
                                            String defaultValue)
        Retrieve a string value from a JSONObject
        Parameters:
        jsonObject - JSONObject to get value from
        property - Property name of the value
        defaultValue - Default value if the property does not exist
        Returns:
        the String value
      • updateValue

        public static void updateValue​(org.json.JSONObject jsonObject,
                                       String property,
                                       String value)
                                throws org.json.JSONException
        Update a String value in an JSONOject
        Parameters:
        jsonObject - JSONObject to update
        property - Name of the property
        value - New value
        Throws:
        org.json.JSONException - if update fails
      • getIntegerValue

        public static Integer getIntegerValue​(org.json.JSONObject jsonObject,
                                              String property,
                                              Integer defaultValue)
        Retrieve an Integer value from a JSONObject
        Parameters:
        jsonObject - JSONObject to get value from
        property - Property name of the value
        defaultValue - Default value if the property does not exist
        Returns:
        the Integer value
      • updateValue

        public static void updateValue​(org.json.JSONObject jsonObject,
                                       String property,
                                       Integer value)
                                throws org.json.JSONException
        Update a Integer value in an JSONOject
        Parameters:
        jsonObject - JSONObject to update
        property - Name of the property
        value - New value
        Throws:
        org.json.JSONException - if update fails
      • getDoubleValue

        public static Double getDoubleValue​(org.json.JSONObject jsonObject,
                                            String property,
                                            Double defaultValue)
        Retrieve an Double value from a JSONObject
        Parameters:
        jsonObject - JSONObject to get value from
        property - Property name of the value
        defaultValue - Default value if the property does not exist
        Returns:
        the Integer value
      • updateValue

        public static void updateValue​(org.json.JSONObject jsonObject,
                                       String property,
                                       Double value)
                                throws org.json.JSONException
        Update a Double value in an JSONOject
        Parameters:
        jsonObject - JSONObject to update
        property - Name of the property
        value - New value
        Throws:
        org.json.JSONException - if update fails
      • getBooleanValue

        public static Boolean getBooleanValue​(org.json.JSONObject jsonObject,
                                              String property,
                                              Boolean defaultValue)
        Retrieve an Boolean value from a JSONObject
        Parameters:
        jsonObject - JSONObject to get value from
        property - Property name of the value
        defaultValue - Default value if the property does not exist
        Returns:
        the Integer value
      • updateValue

        public static void updateValue​(org.json.JSONObject jsonObject,
                                       String property,
                                       Boolean value)
                                throws org.json.JSONException
        Update a Boolean value in an JSONOject
        Parameters:
        jsonObject - JSONObject to update
        property - Name of the property
        value - New value
        Throws:
        org.json.JSONException - if update fails
      • getJsonValue

        public static org.json.JSONObject getJsonValue​(org.json.JSONObject jsonObject,
                                                       String property,
                                                       org.json.JSONObject defaultValue)
        Retrieve an JSONObject value from a JSONObject
        Parameters:
        jsonObject - JSONObject to get value from
        property - Property name of the value
        defaultValue - Default value if the property does not exist
        Returns:
        the Integer value
      • updateValue

        public static void updateValue​(org.json.JSONObject jsonObject,
                                       String property,
                                       org.json.JSONObject value)
                                throws org.json.JSONException
        Update a JSONObject value in an JSONOject
        Parameters:
        jsonObject - to update
        property - Name of the property
        value - New value
        Throws:
        org.json.JSONException - if update fails
      • getJsonArray

        public static org.json.JSONArray getJsonArray​(org.json.JSONObject jsonObject,
                                                      String property,
                                                      org.json.JSONArray defaultValue)
        Retrieve an JSONArray value from a JSONObject
        Parameters:
        jsonObject - JSONObject to get value from
        property - Property name of the value
        defaultValue - Default value if the property does not exist
        Returns:
        the Integer value
      • updateValue

        public static void updateValue​(org.json.JSONObject jsonObject,
                                       String property,
                                       org.json.JSONArray value)
                                throws org.json.JSONException
        Update a JSONArray value in an JSONOject
        Parameters:
        jsonObject - to update
        property - Name of the property
        value - New value
        Throws:
        org.json.JSONException - if update fails