Android Open Source - json-interface Json Object Interface






From Project

Back to project page json-interface.

License

The source code is released under:

MIT License

If you think the Android project json-interface listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * This file is part of JSON Interface library.
 * Copyright (C) 2014 Noor Dawod. All rights reserved.
 * https://github.com/noordawod/json-interface
 */*from w ww.  ja va2 s.  co  m*/
 * Released under the MIT license
 * http://en.wikipedia.org/wiki/MIT_License
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to
 * deal in the Software without restriction, including without limitation the
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 * sell copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

package com.fine47.json;

import android.os.Parcelable;
import java.util.Map;

/**
 * Main interface for manipulating JSON objects. Pay attention that due to the
 * important rule played by {@link Parcelable} class in Android, this interface
 * extends the former for your convenience.
 *
 * @since 1.0
 */
public interface JsonObjectInterface extends JsonInterface {

  /**
   * Reusable logging tag for any JSON object implementation.
   */
  public final static String LOG_TAG = "JsonObject";

  /**
   * Checks whether this JSON object contains the specified key.
   *
   * @param key to check if it's contained in this JSON object
   * @return TRUE if key is contained in this JSON object, FALSE otherwise
   */
  public boolean contains(String key);

  /**
   * Returns the value contained in this JSON object for the specified key and
   * specified type. If the key is not found, or the value is of a different
   * type, NULL is returned.
   *
   * @param <T> type of the value to return
   * @param key corresponding to the value to return
   * @return the value for the specified key, NULL if not found
   */
  public <T> T get(String key);

  /**
   * Returns the value contained in this JSON object for the specified key and
   * specified type. If the key is not found, or the value is of a different
   * type, the specified default value is returned.
   *
   * @param <T> type of the value to return
   * @param key corresponding to the value to return
   * @param defValue default value to return in case of error
   * @return the value for the specified key, NULL if not found
   */
  public <T> T get(String key, T defValue);

  /**
   * Sets the specified String value corresponding to the specified key in this
   * JSON object.
   *
   * @param key for which to set the value
   * @param value to set in this JSON object for the specified key
   */
  public void add(String key, Object value);

  /**
   * Removes the specified key from this JSON object. If the key is not present,
   * nothing happens.
   *
   * @param key to remove from this JSON object
   */
  public void remove(String key);

  /**
   * Merges the data contained in the specified Android-native JSON data object
   * into this JSON object.
   *
   * @param json to merge in into this JSON object
   */
  public void merge(org.json.JSONObject json);

  /**
   * Merges the data contained in the specified JSON data object into this
   * JSON object.
   *
   * @param json to merge in into this JSON object
   */
  public void merge(JsonObjectInterface json);

  /**
   * Merges the data contained in the specified list into this JSON object.
   *
   * @param map to merge in into this JSON object
   */
  public void merge(Map map);

  /**
   * Clones the K:V tuples contained within this JSON object and returns them
   * in a new JSON object.
   *
   * @return cloned JSON object
   */
  public JsonObjectInterface clone();

  /**
   * Returns all keys of this JSON object. Though these keys, one is able to
   * cycle through the values of each using {@link #get(java.lang.String)}
   * method.
   *
   * @return list of all keys in this JSON object (could be an empty list, too)
   */
  public String[] keys();
}




Java Source Code List

com.fine47.json.JsonArrayInterface.java
com.fine47.json.JsonInterface.java
com.fine47.json.JsonObjectInterface.java
com.fine47.json.Marshaller.java
com.fine47.json.builtin.JsonArray.java
com.fine47.json.builtin.JsonObject.java
com.fine47.json.builtin.JsonUtil.java
com.fine47.json.simple.JsonArray.java
com.fine47.json.simple.JsonObject.java
com.fine47.json.simple.JsonUtil.java