當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject.NULL屬性代碼示例

本文整理匯總了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;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:39,代碼來源:JSONtoFmModel.java

示例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;
}
 
開發者ID:whitedogg13,項目名稱:react-native-nfc-manager,代碼行數:23,代碼來源:JsonConvert.java

示例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;
    }
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:26,代碼來源:Decompressor.java

示例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);
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:20,代碼來源:JsonConverter.java

示例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;
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:18,代碼來源:JsonConverter.java

示例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;
}
 
開發者ID:Spajker7,項目名稱:PiYouTube,代碼行數:18,代碼來源:Option.java

示例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;
    }
}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:11,代碼來源:JsonHelper.java

示例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());
  }
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:40,代碼來源:TypeUtils.java

示例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());
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:29,代碼來源:OpenGraphJSONUtility.java

示例10: toString

@Override
public String toString(Object value) {
    if (value == null || value == JSONObject.NULL) {
        return "";
    } else {
        return value.toString();
    }
}
 
開發者ID:pascalgn,項目名稱:jiracli,代碼行數:8,代碼來源:ConverterProvider.java

示例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());
    }
}
 
開發者ID:MobileDev418,項目名稱:chat-sdk-android-push-firebase,代碼行數:38,代碼來源:Response.java

示例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();
	}
}
 
開發者ID:rapid-io,項目名稱:rapid-io-android,代碼行數:10,代碼來源:FilterValue.java

示例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);
    }
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:29,代碼來源:JSONScriptElement.java

示例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());
}
 
開發者ID:steelkiwi,項目名稱:ErrorParser,代碼行數:7,代碼來源:Parser.java

示例15: checkNull

private Object checkNull(Object obj) {
    if (obj == JSONObject.NULL) {
        return null;
    }
    return obj;
}
 
開發者ID:adobe,項目名稱:stock-api-sdk,代碼行數:6,代碼來源:JsonUtilsTest.java


注:本文中的org.json.JSONObject.NULL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。