org.json.JSONObject.putOnce()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(1972)

本文整理了Java中org.json.JSONObject.putOnce()方法的一些代码示例,展示了JSONObject.putOnce()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.putOnce()方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:putOnce

JSONObject.putOnce介绍

[英]Put a key/value pair in the JSONObject, but only if the key and the value are both non-null, and only if there is not already a member with that name.
[中]在JSONObject中放置一个键/值对,但前提是键和值都为非null,并且还没有具有该名称的成员。

代码示例

代码示例来源:origin: zzz40500/GsonFormat

/**
 * Construct a JSONObject from a subset of another JSONObject. An array of
 * strings is used to identify the keys that should be copied. Missing keys
 * are ignored.
 *
 * @param jo
 *            A JSONObject.
 * @param names
 *            An array of strings.
 * @throws JSONException
 * @exception JSONException
 *                If a value is a non-finite number or if a name is
 *                duplicated.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      this.putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: loklak/loklak_server

/**
 * Construct a JSONObject from a subset of another JSONObject. An array of
 * strings is used to identify the keys that should be copied. Missing keys
 * are ignored.
 *
 * @param jo
 *            A JSONObject.
 * @param names
 *            An array of strings.
 */
public JSONObject(JSONObject jo, String[] names) {
  this(names.length);
  for (int i = 0; i < names.length; i += 1) {
    try {
      this.putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: zzz40500/GsonFormat

throw x.syntaxError("Expected a ':' after a key");
this.putOnce(key, x.nextValue());

代码示例来源:origin: b3log/latke

/**
 * Construct a JSONObject from a subset of another JSONObject. An array of
 * strings is used to identify the keys that should be copied. Missing keys
 * are ignored.
 *
 * @param jo
 *            A JSONObject.
 * @param names
 *            An array of strings.
 */
public JSONObject(JSONObject jo, String[] names) {
  this(names.length);
  for (int i = 0; i < names.length; i += 1) {
    try {
      this.putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: uk.org.retep.tools/util

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) throws JSONException {
  this();
  for (int i = 0; i < names.length; i += 1) {
    putOnce(names[i], jo.opt(names[i]));
  }
}

代码示例来源:origin: org.datanucleus/datanucleus-api-json

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) throws JSONException {
  this();
  for (int i = 0; i < names.length; i += 1) {
    putOnce(names[i], jo.opt(names[i]));
  }
}

代码示例来源:origin: fernandospr/javapns-jdk16

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) throws JSONException {
  this();
  for (int i = 0; i < names.length; i += 1) {
    putOnce(names[i], jo.opt(names[i]));
  }
}

代码示例来源:origin: org.daisy.libs/com.xmlcalabash

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 */
public JSONObject(JSONObject jo, String[] names) throws JSONException {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: io.snappydata/gemfire-core

/**
 * 
 * @param key
 * @param value
 * @return this GfJsonObject
 * @throws GfJsonException
 *           if the key is a duplicate
 */
public GfJsonObject putOnce(String key, Object value) throws GfJsonException {
 try {
  jsonObject.putOnce(key, value);
 } catch (JSONException e) {
  throw new GfJsonException(e.getMessage());
 }
 return this;
}

代码示例来源:origin: org.apache.geode/gemfire-core

/**
 * 
 * @param key
 * @param value
 * @return this GfJsonObject
 * @throws GfJsonException
 *           if the key is a duplicate
 */
public GfJsonObject putOnce(String key, Object value) throws GfJsonException {
 try {
  jsonObject.putOnce(key, value);
 } catch (JSONException e) {
  throw new GfJsonException(e.getMessage());
 }
 return this;
}

代码示例来源:origin: com.xmlcalabash/xmlcalabash

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: com.barchart.wrap/barchart-wrap-jackson

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @throws JSONException
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      this.putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: com.unboundid.components/json

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @throws JSONException 
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: org.b3log/latke

/**
 * Construct a JSONObject from a subset of another JSONObject. An array of
 * strings is used to identify the keys that should be copied. Missing keys
 * are ignored.
 *
 * @param jo
 *            A JSONObject.
 * @param names
 *            An array of strings.
 */
public JSONObject(JSONObject jo, String[] names) {
  this(names.length);
  for (int i = 0; i < names.length; i += 1) {
    try {
      this.putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: io.snappydata/gemfire-util

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @throws JSONException
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      this.putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: org.json/com.springsource.org.json

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @throws JSONException 
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: io.snappydata/gemfire-json

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @throws JSONException
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      this.putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: org.owasp.jbrofuzz/jbrofuzz

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @throws JSONException 
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: quux00/hive-json-schema

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @throws JSONException 
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      putOnce(names[i].toLowerCase(), jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

代码示例来源:origin: aruld/java-oneliners

/**
 * Construct a JSONObject from a subset of another JSONObject.
 * An array of strings is used to identify the keys that should be copied.
 * Missing keys are ignored.
 * @param jo A JSONObject.
 * @param names An array of strings.
 * @throws JSONException
 * @exception JSONException If a value is a non-finite number or if a name is duplicated.
 */
public JSONObject(JSONObject jo, String[] names) {
  this();
  for (int i = 0; i < names.length; i += 1) {
    try {
      this.putOnce(names[i], jo.opt(names[i]));
    } catch (Exception ignore) {
    }
  }
}

相关文章

JSONObject类方法