本文整理了Java中org.json.JSONObject.putOpt()
方法的一些代码示例,展示了JSONObject.putOpt()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.putOpt()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:putOpt
[英]Equivalent to put(name, value) when both parameters are non-null; does nothing otherwise.
[中]当两个参数均非空时,等效于put(名称、值);否则什么也不做。
代码示例来源:origin: zzz40500/GsonFormat
/**
* Construct a JSONObject from an Object, using reflection to find the
* public members. The resulting JSONObject's keys will be the strings from
* the names array, and the values will be the field values associated with
* those keys in the object. If a key is not found or not visible, then it
* will not be copied into the new JSONObject.
*
* @param object
* An object that has fields that should be used to make a
* JSONObject.
* @param names
* An array of strings, the names of the fields to be obtained
* from the object.
*/
public JSONObject(Object object, String names[]) {
this();
Class c = object.getClass();
for (int i = 0; i < names.length; i += 1) {
String name = names[i];
try {
this.putOpt(name, c.getField(name).get(object));
} catch (Exception ignore) {
}
}
}
代码示例来源:origin: apache/geode
/**
*
* @return this GfJsonObject
* @throws GfJsonException If the value is a non-finite number.
*/
public GfJsonObject put(String key, Collection<?> value) throws GfJsonException {
try {
jsonObject.putOpt(key, value);
} catch (JSONException e) {
throw new GfJsonException(e.getMessage());
}
return this;
}
代码示例来源:origin: loklak/loklak_server
/**
* Construct a JSONObject from an Object, using reflection to find the
* public members. The resulting JSONObject's keys will be the strings from
* the names array, and the values will be the field values associated with
* those keys in the object. If a key is not found or not visible, then it
* will not be copied into the new JSONObject.
*
* @param object
* An object that has fields that should be used to make a
* JSONObject.
* @param names
* An array of strings, the names of the fields to be obtained
* from the object.
*/
public JSONObject(Object object, String names[]) {
this(names.length);
Class<?> c = object.getClass();
for (int i = 0; i < names.length; i += 1) {
String name = names[i];
try {
this.putOpt(name, c.getField(name).get(object));
} catch (Exception ignore) {
}
}
}
代码示例来源:origin: apache/geode
public GfJsonObject putJSONArray(String key, GfJsonArray value) throws GfJsonException {
try {
jsonObject.putOpt(key, value.getInternalJsonArray());
} catch (JSONException e) {
throw new GfJsonException(e.getMessage());
}
return this;
}
代码示例来源:origin: apache/geode
/**
*
* @return this GfJsonObject
* @throws GfJsonException If the value is a non-finite number.
*/
public GfJsonObject putOpt(String key, Object value) throws GfJsonException {
try {
jsonObject.putOpt(key, extractInternalForGfJsonOrReturnSame(value));
} catch (JSONException e) {
throw new GfJsonException(e.getMessage());
}
return this;
}
代码示例来源:origin: facebook/facebook-android-sdk
static void jsonObjectPutAll(JSONObject jsonObject, Map<String, Object> map) {
Set<Map.Entry<String, Object>> entrySet = map.entrySet();
for (Map.Entry<String, Object> entry : entrySet) {
try {
jsonObject.putOpt(entry.getKey(), entry.getValue());
} catch (JSONException e) {
throw new IllegalArgumentException(e);
}
}
}
代码示例来源:origin: facebook/facebook-android-sdk
json.putOpt(JSON_VALUE, jsonArray);
代码示例来源:origin: facebook/facebook-android-sdk
public static Object getStringPropertyAsJSON(
JSONObject jsonObject,
String key,
String nonJSONPropertyKey
) throws JSONException {
Object value = jsonObject.opt(key);
if (value != null && value instanceof String) {
JSONTokener tokener = new JSONTokener((String) value);
value = tokener.nextValue();
}
if (value != null && !(value instanceof JSONObject || value instanceof JSONArray)) {
if (nonJSONPropertyKey != null) {
// Facebook sometimes gives us back a non-JSON value such as
// literal "true" or "false" as a result.
// If we got something like that, we present it to the caller as a JSONObject
// with a single property. We only do this if the caller wants that behavior.
jsonObject = new JSONObject();
jsonObject.putOpt(nonJSONPropertyKey, value);
return jsonObject;
} else {
throw new FacebookException("Got an unexpected non-JSON object.");
}
}
return value;
}
代码示例来源:origin: parse-community/Parse-SDK-Android
/**
* Serializes the history state to a JSON object using the format described in loadJSON().
*/
public JSONObject toJSON() throws JSONException {
JSONObject json = new JSONObject();
if (entries.size() > 0) {
JSONObject history = new JSONObject();
for (Entry e : entries) {
history.put(e.pushId, e.timestamp);
}
json.put("seen", history);
}
json.putOpt("lastTime", lastTime);
return json;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
public JSONBuilder withAttribute(String key, Object value) {
Object jsonValue = value instanceof JSONSerializable ? ((JSONSerializable) value)
.toJSONObject() : value;
try {
json.putOpt(key, jsonValue);
} catch (JSONException e) {
// somehow value is Double or Float NaN or Infinity, so ignore
}
return this;
}
代码示例来源:origin: b3log/latke
/**
* Construct a JSONObject from an Object, using reflection to find the
* public members. The resulting JSONObject's keys will be the strings from
* the names array, and the values will be the field values associated with
* those keys in the object. If a key is not found or not visible, then it
* will not be copied into the new JSONObject.
*
* @param object
* An object that has fields that should be used to make a
* JSONObject.
* @param names
* An array of strings, the names of the fields to be obtained
* from the object.
*/
public JSONObject(Object object, String names[]) {
this(names.length);
Class<?> c = object.getClass();
for (int i = 0; i < names.length; i += 1) {
String name = names[i];
try {
this.putOpt(name, c.getField(name).get(object));
} catch (Exception ignore) {
}
}
}
代码示例来源:origin: aws-amplify/aws-sdk-android
public JSONBuilder withAttribute(String key, Object value) {
final Object jsonValue = value instanceof JSONSerializable
? ((JSONSerializable) value).toJSONObject()
: value;
try {
json.putOpt(key, jsonValue);
} catch (final JSONException e) {
LOGGER.warn("error parsing json", e);
}
return this;
}
代码示例来源:origin: aws-amplify/aws-sdk-android
recordJson.put(STREAM_NAME_FIELD, source.getStreamName());
recordJson.put(PARTITION_KEY_FIELD, source.getPartitionKey());
recordJson.putOpt(EXPLICIT_HASH_FIELD, source.getExplicitHashKey());
recordJson.putOpt(SEQUENCE_NUMBER_FIELD, source.getSequenceNumberForOrdering());
} catch (final JSONException e) {
throw new AmazonClientException("Unable to convert KinesisRecord to JSON "
代码示例来源:origin: fr.avianey/facebook-android-api
static void jsonObjectPutAll(JSONObject jsonObject, Map<String, Object> map) {
Set<Map.Entry<String, Object>> entrySet = map.entrySet();
for (Map.Entry<String, Object> entry : entrySet) {
try {
jsonObject.putOpt(entry.getKey(), entry.getValue());
} catch (JSONException e) {
throw new IllegalArgumentException(e);
}
}
}
代码示例来源:origin: drakeet/Floo
@NonNull
private JSONObject toJsonObject(@NonNull Target target) throws JSONException {
final JSONObject jsonObject = new JSONObject();
jsonObject.putOpt(TARGET_URL, target.getUrl());
return jsonObject;
}
代码示例来源:origin: luckybilly/DebugController
private void initData() {
JSONObject json = new JSONObject();
for (String type : SWITCH_PARAM_LIST) {
try{
json.putOpt(type, "");
} catch(Exception e) {
e.printStackTrace();
}
}
ServerMessageProcessorManager.sendMessageToClient(EnvSwitchActivity.this, "get" + json.toString());
}
代码示例来源:origin: org.visallo/visallo-core
protected void broadcastWorkProductChange(String workProductId, String skipSourceGuid, String workspaceId, JSONObject permissions) {
JSONObject json = new JSONObject();
json.put("type", "workProductChange");
json.put("permissions", permissions);
JSONObject dataJson = new JSONObject();
dataJson.put("id", workProductId);
dataJson.put("workspaceId", workspaceId);
dataJson.putOpt("sourceGuid", skipSourceGuid);
json.put("data", dataJson);
broadcastJson(json);
}
代码示例来源:origin: org.visallo/visallo-core
public void broadcastWorkProductAncillaryChange(String workProductId, String workspaceId, String ancillaryId, User user, String skipSourceGuid) {
JSONObject json = new JSONObject();
json.put("type", "workProductAncillaryChange");
json.put("permissions", getPermissionsWithWorkspace(workspaceId));
JSONObject dataJson = new JSONObject();
dataJson.put("id", ancillaryId);
dataJson.put("workspaceId", workspaceId);
dataJson.put("productId", workProductId);
dataJson.putOpt("sourceGuid", skipSourceGuid);
json.put("data", dataJson);
broadcastJson(json);
}
代码示例来源:origin: org.opendaylight.netconf/sal-rest-docgen
private static void processEnumType(final EnumTypeDefinition enumLeafType, final JSONObject property) throws JSONException {
List<EnumPair> enumPairs = enumLeafType.getValues();
List<String> enumNames = new ArrayList<>();
for (EnumPair enumPair : enumPairs) {
enumNames.add(enumPair.getName());
}
property.putOpt(ENUM, new JSONArray(enumNames));
}
代码示例来源:origin: org.qcri.rheem/rheem-core
@Override
public JSONObject toJson() {
JSONObject json = new JSONObject();
json.put("cpu", JsonSerializables.serialize(this.cpuUsage, false));
json.put("ram", JsonSerializables.serialize(this.ramUsage, false));
json.putOpt("network", JsonSerializables.serialize(this.networkUsage, false));
json.putOpt("disk", JsonSerializables.serialize(this.diskUsage, false));
json.put("utilization", this.resourceUtilization);
json.put("overhead", this.overheadMillis);
return json;
}
内容来源于网络,如有侵权,请联系作者删除!