本文整理汇总了Java中org.json.JSONObject.NULL属性的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.NULL属性的具体用法?Java JSONObject.NULL怎么用?Java JSONObject.NULL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.NULL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertJSONObjectToMap
/**
* JSONObject is an unordered collection of name/value pairs -> convert to Map (equivalent to Freemarker "hash")
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> convertJSONObjectToMap(JSONObject jo) throws JSONException
{
Map<String, Object> model = new HashMap<String, Object>();
Iterator<String> itr = (Iterator<String>)jo.keys();
while (itr.hasNext())
{
String key = (String)itr.next();
Object o = jo.get(key);
if (o instanceof JSONObject)
{
model.put(key, convertJSONObjectToMap((JSONObject)o));
}
else if (o instanceof JSONArray)
{
model.put(key, convertJSONArrayToList((JSONArray)o));
}
else if (o == JSONObject.NULL)
{
model.put(key, null); // note: http://freemarker.org/docs/dgui_template_exp.html#dgui_template_exp_missing
}
else
{
if ((o instanceof String) && autoConvertISO8601 && (matcherISO8601.matcher((String)o).matches()))
{
o = ISO8601DateFormat.parse((String)o);
}
model.put(key, o);
}
}
return model;
}
示例2: jsonToReact
public static WritableMap jsonToReact(JSONObject jsonObject) throws JSONException {
WritableMap writableMap = Arguments.createMap();
Iterator iterator = jsonObject.keys();
while(iterator.hasNext()) {
String key = (String) iterator.next();
Object value = jsonObject.get(key);
if (value instanceof Float || value instanceof Double) {
writableMap.putDouble(key, jsonObject.getDouble(key));
} else if (value instanceof Number) {
writableMap.putInt(key, jsonObject.getInt(key));
} else if (value instanceof String) {
writableMap.putString(key, jsonObject.getString(key));
} else if (value instanceof JSONObject) {
writableMap.putMap(key,jsonToReact(jsonObject.getJSONObject(key)));
} else if (value instanceof JSONArray){
writableMap.putArray(key, jsonToReact(jsonObject.getJSONArray(key)));
} else if (value == JSONObject.NULL){
writableMap.putNull(key);
}
}
return writableMap;
}
示例3: readJSON
/**
* Read a JSON value. The type of value is determined by the next 3 bits.
*
* @return
* @throws JSONException
*/
private Object readJSON() throws JSONException {
switch (read(3)) {
case zipObject:
return readObject();
case zipArrayString:
return readArray(true);
case zipArrayValue:
return readArray(false);
case zipEmptyObject:
return new JSONObject();
case zipEmptyArray:
return new JSONArray();
case zipTrue:
return Boolean.TRUE;
case zipFalse:
return Boolean.FALSE;
default:
return JSONObject.NULL;
}
}
示例4: listFromJson
public static <T> List<T> listFromJson(JSONArray json) {
if (json == null) {
return null;
}
List<Object> result = new ArrayList<>(json.length());
for (int i = 0; i < json.length(); i++) {
Object value = json.opt(i);
if (value == null || value == JSONObject.NULL) {
value = null;
} else if (value instanceof JSONObject) {
value = mapFromJson((JSONObject) value);
} else if (value instanceof JSONArray) {
value = listFromJson((JSONArray) value);
} else if (JSONObject.NULL.equals(value)) {
value = null;
}
result.add(value);
}
return CollectionUtil.uncheckedCast(result);
}
示例5: listToJsonArray
public static JSONArray listToJsonArray(Iterable<?> list) throws JSONException {
if (list == null) {
return null;
}
JSONArray obj = new JSONArray();
for (Object value : list) {
if (value instanceof Map) {
Map<String, ?> mappedValue = CollectionUtil.uncheckedCast(value);
value = mapToJsonObject(mappedValue);
} else if (value instanceof Iterable) {
value = listToJsonArray((Iterable<?>) value);
} else if (value == null) {
value = JSONObject.NULL;
}
obj.put(value);
}
return obj;
}
示例6: processValue
public static Object processValue(String name, Object value)
{
if("iface".equals(name) && "all".equals(value))
{
value = null;
}
else if("chrome".equals(name) && "auto".equals(value))
{
value = null;
}
if(value == null)
{
value = JSONObject.NULL;
}
return value;
}
示例7: fromJson
private static Object fromJson(Object json) throws JSONException {
if (json == JSONObject.NULL) {
return null;
} else if (json instanceof JSONObject) {
return toMap((JSONObject) json);
} else if (json instanceof JSONArray) {
return toList((JSONArray) json);
} else {
return json;
}
}
示例8: jsonToObject
/**
* Convert the specified complex JSON object to the respective Java types using the specified
* object type that has the actual type definition.
*
* @param jObject the JSON object
* @param type the object type to be used for conversion
* @return the respective Java object representation using the specified type
* @throws JSONException
*/
public static Object jsonToObject(final Object jObject, final DataType type)
throws JSONException {
if (jObject == null || jObject == JSONObject.NULL) {
return null;
}
/** convert from JSON-string to the respective Java object **/
if (type instanceof WrapperType) {
return jsonToObject(jObject, ((WrapperType) type).getBasicObjectType());
} else if (type instanceof BasicTypes) {
if (BasicTypes.BINARY.equals(type)) {
return toArray(BINARY_TYPE, (JSONArray) jObject);
} else {
final Function<String, Object> function = STRING_TO_TYPE_CONVERT_MAP.get(type);
if (function == null) {
throw new IllegalArgumentException("Unsupported type: " + type.toString());
}
return function.apply((String) jObject);
}
} else if (type instanceof ListType) {
return toArray((ListType) type, (JSONArray) jObject);
} else if (type instanceof MapType) {
return toMap((MapType) type, (JSONObject) jObject);
} else if (type instanceof StructType) {
return toStruct((StructType) type, (JSONArray) jObject);
} else if (type instanceof UnionType) {
return toUnion((UnionType) type, (JSONArray) jObject);
} else {
throw new IllegalArgumentException("Unsupported type: " + type.toString());
}
}
示例9: toJSONValue
public static Object toJSONValue(
@Nullable final Object object,
final PhotoJSONProcessor photoJSONProcessor) throws JSONException {
if (object == null) {
return JSONObject.NULL;
}
if ((object instanceof String) ||
(object instanceof Boolean) ||
(object instanceof Double) ||
(object instanceof Float) ||
(object instanceof Integer) ||
(object instanceof Long)) {
return object;
}
if (object instanceof SharePhoto) {
if (photoJSONProcessor != null) {
return photoJSONProcessor.toJSONObject((SharePhoto) object);
}
return null;
}
if (object instanceof ShareOpenGraphObject) {
return toJSONObject((ShareOpenGraphObject) object, photoJSONProcessor);
}
if (object instanceof List) {
return toJSONArray((List) object, photoJSONProcessor);
}
throw new IllegalArgumentException(
"Invalid object found for JSON serialization: " +object.toString());
}
示例10: toString
@Override
public String toString(Object value) {
if (value == null || value == JSONObject.NULL) {
return "";
} else {
return value.toString();
}
}
示例11: createResponseFromObject
private static Response createResponseFromObject(Request request, HttpURLConnection connection, Object object,
boolean isFromCache, Object originalResult) throws JSONException {
if (object instanceof JSONObject) {
JSONObject jsonObject = (JSONObject) object;
FacebookRequestError error =
FacebookRequestError.checkResponseAndCreateError(jsonObject, originalResult, connection);
if (error != null) {
if (error.getErrorCode() == INVALID_SESSION_FACEBOOK_ERROR_CODE) {
Session session = request.getSession();
if (session != null) {
session.closeAndClearTokenInformation();
}
}
return new Response(request, connection, error);
}
Object body = Utility.getStringPropertyAsJSON(jsonObject, BODY_KEY, NON_JSON_RESPONSE_PROPERTY);
if (body instanceof JSONObject) {
GraphObject graphObject = GraphObject.Factory.create((JSONObject) body);
return new Response(request, connection, body.toString(), graphObject, isFromCache);
} else if (body instanceof JSONArray) {
GraphObjectList<GraphObject> graphObjectList = GraphObject.Factory.createList(
(JSONArray) body, GraphObject.class);
return new Response(request, connection, body.toString(), graphObjectList, isFromCache);
}
// We didn't get a body we understand how to handle, so pretend we got nothing.
object = JSONObject.NULL;
}
if (object == JSONObject.NULL) {
return new Response(request, connection, object.toString(), (GraphObject)null, isFromCache);
} else {
throw new FacebookException("Got unexpected object type in response, class: "
+ object.getClass().getSimpleName());
}
}
示例12: toJson
@Override
public Object toJson() throws JSONException {
if(compareType.equals(TYPE_EQUAL)) {
return value != null ? value : JSONObject.NULL;
} else {
JSONObject root = new JSONObject();
root.put(compareType, value != null ? value : JSONObject.NULL);
return root.toString();
}
}
示例13: enscriptAssert
private String enscriptAssert(String type) {
String property = event.getString("property");
String cellinfo = null;
if (event.has("cellinfo")) {
cellinfo = event.getString("cellinfo");
}
String method = "assert_p";
if (event.has("method")) {
method = event.getString("method");
} else {
if (type.equals("wait")) {
method = "wait_p";
} else if (property.equalsIgnoreCase("content")) {
method = "assert_content";
}
}
Object value = event.get("value");
if (value == null || value == JSONObject.NULL)
value = "";
if (method.equals("assert_content")) {
return Indent.getIndent() + ScriptModel.getModel().getScriptCodeForGenericAction(method, name, value);
}
if (cellinfo == null || "".equals(cellinfo)) {
return Indent.getIndent() + ScriptModel.getModel().getScriptCodeForGenericAction(method, name, property, value);
} else {
return Indent.getIndent()
+ ScriptModel.getModel().getScriptCodeForGenericAction(method, name, property, value, cellinfo);
}
}
示例14: jsonToMap
private static void jsonToMap(String source) throws JSONException {
JSONObject json = new JSONObject(source);
if (json != JSONObject.NULL) {
notNestingMap = toMap(json);
}
Log.d(TAG, "cleared map - " + clearedMap.toString());
}
示例15: checkNull
private Object checkNull(Object obj) {
if (obj == JSONObject.NULL) {
return null;
}
return obj;
}