当前位置: 首页>>代码示例>>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;未经允许,请勿转载。