本文整理了Java中org.json.JSONObject.optEnum()
方法的一些代码示例,展示了JSONObject.optEnum()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.optEnum()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:optEnum
[英]Get the enum value associated with a key.
[中]
代码示例来源:origin: loklak/loklak_server
/**
* Get the enum value associated with a key.
*
* @param clazz
* The type of enum to retrieve.
* @param key
* A key string.
* @return The enum value associated with the key or null if not found
*/
public <E extends Enum<E>> E optEnum(Class<E> clazz, String key) {
return this.optEnum(clazz, key, null);
}
代码示例来源:origin: loklak/loklak_server
/**
* Get the enum value associated with a key.
*
* @param clazz
* The type of enum to retrieve.
* @param key
* A key string.
* @return The enum value associated with the key
* @throws JSONException
* if the key is not found or if the value cannot be converted
* to an enum.
*/
public <E extends Enum<E>> E getEnum(Class<E> clazz, String key) throws JSONException {
E val = optEnum(clazz, key);
if(val==null) {
// JSONException should really take a throwable argument.
// If it did, I would re-implement this with the Enum.valueOf
// method and place any thrown exception in the JSONException
throw new JSONException("JSONObject[" + quote(key)
+ "] is not an enum of type " + quote(clazz.getSimpleName())
+ ".");
}
return val;
}
代码示例来源:origin: b3log/latke
/**
* Get the enum value associated with a key.
*
* @param <E>
* Enum Type
* @param clazz
* The type of enum to retrieve.
* @param key
* A key string.
* @return The enum value associated with the key or null if not found
*/
public <E extends Enum<E>> E optEnum(Class<E> clazz, String key) {
return this.optEnum(clazz, key, null);
}
代码示例来源:origin: b3log/latke
/**
* Get the enum value associated with a key.
*
* @param <E>
* Enum Type
* @param clazz
* The type of enum to retrieve.
* @param key
* A key string.
* @return The enum value associated with the key
* @throws JSONException
* if the key is not found or if the value cannot be converted
* to an enum.
*/
public <E extends Enum<E>> E getEnum(Class<E> clazz, String key) throws JSONException {
E val = optEnum(clazz, key);
if(val==null) {
// JSONException should really take a throwable argument.
// If it did, I would re-implement this with the Enum.valueOf
// method and place any thrown exception in the JSONException
throw new JSONException("JSONObject[" + quote(key)
+ "] is not an enum of type " + quote(clazz.getSimpleName())
+ ".");
}
return val;
}
代码示例来源:origin: org.codeartisans/org.json
/**
* Get the enum value associated with a key.
*
* @param clazz
* The type of enum to retrieve.
* @param key
* A key string.
* @return The enum value associated with the key or null if not found
*/
public <E extends Enum<E>> E optEnum(Class<E> clazz, String key) {
return this.optEnum(clazz, key, null);
}
代码示例来源:origin: org.b3log/latke
/**
* Get the enum value associated with a key.
*
* @param <E>
* Enum Type
* @param clazz
* The type of enum to retrieve.
* @param key
* A key string.
* @return The enum value associated with the key or null if not found
*/
public <E extends Enum<E>> E optEnum(Class<E> clazz, String key) {
return this.optEnum(clazz, key, null);
}
代码示例来源:origin: org.codeartisans/org.json
/**
* Get the enum value associated with a key.
*
* @param clazz
* The type of enum to retrieve.
* @param key
* A key string.
* @return The enum value associated with the key
* @throws JSONException
* if the key is not found or if the value cannot be converted
* to an enum.
*/
public <E extends Enum<E>> E getEnum(Class<E> clazz, String key) throws JSONException {
E val = optEnum(clazz, key);
if(val==null) {
// JSONException should really take a throwable argument.
// If it did, I would re-implement this with the Enum.valueOf
// method and place any thrown exception in the JSONException
throw new JSONException("JSONObject[" + quote(key)
+ "] is not an enum of type " + quote(clazz.getSimpleName())
+ ".");
}
return val;
}
代码示例来源:origin: org.b3log/latke
/**
* Get the enum value associated with a key.
*
* @param <E>
* Enum Type
* @param clazz
* The type of enum to retrieve.
* @param key
* A key string.
* @return The enum value associated with the key
* @throws JSONException
* if the key is not found or if the value cannot be converted
* to an enum.
*/
public <E extends Enum<E>> E getEnum(Class<E> clazz, String key) throws JSONException {
E val = optEnum(clazz, key);
if(val==null) {
// JSONException should really take a throwable argument.
// If it did, I would re-implement this with the Enum.valueOf
// method and place any thrown exception in the JSONException
throw new JSONException("JSONObject[" + quote(key)
+ "] is not an enum of type " + quote(clazz.getSimpleName())
+ ".");
}
return val;
}
内容来源于网络,如有侵权,请联系作者删除!