本文整理了Java中com.github.openjson.JSONObject.keySet()
方法的一些代码示例,展示了JSONObject.keySet()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.keySet()
方法的具体详情如下:
包路径:com.github.openjson.JSONObject
类名称:JSONObject
方法名:keySet
[英]Returns the set of String names in this object. The returned set is a view of the keys in this object. Set#remove(Object) will remove the corresponding mapping from this object and set iterator behaviour is undefined if this object is modified after it is returned. See #keys().
[中]返回此对象中的字符串名称集。返回的集合是此对象中键的视图。Set#remove(Object)将从此对象中删除相应的映射,如果此对象在返回后被修改,则Set迭代器行为未定义。请参见#keys()。
代码示例来源:origin: com.github.openjson/openjson
public static String[] getNames(JSONObject x) {
Set<String> names = x.keySet();
String[] r = new String[names.size()];
int i = 0;
for (String name : names) {
r[i++] = name;
}
return r;
}
代码示例来源:origin: triplea-game/triplea
/**
* Converts the properties of the specified JSON object into a map of equivalent Java types. Any {@link JSONArray}
* property value will be converted into an equivalent {@code List<Object>}; any {@link JSONObject} property value
* will be converted into an equivalent {@code Map<String, Object>}.
*
* @param jsonObject The JSON object.
*
* @return A map of the specified JSON object's properties converted to their equivalent Java types. The keys are the
* property names; the values are the property values.
*/
public static Map<String, Object> toMap(final JSONObject jsonObject) {
checkNotNull(jsonObject);
final Map<String, Object> map = new HashMap<>(jsonObject.length());
for (final String name : jsonObject.keySet()) {
map.put(name, unwrap(jsonObject.get(name)));
}
return map;
}
}
代码示例来源:origin: org.wicketstuff/wicket-gchart
/**
* Build instance from a JSONobject.
*
* @param json JSON object to build map from. If this contains other
* JSONObjects nested, a corresponding nested structure of ChartOptions will
* be built.
* @return New instance with data from the JSONObject.
*/
public static ChartOptions fromJson(JSONObject json) {
ChartOptions chartOptions = new ChartOptions();
for (String key : json.keySet()) {
Object obj = json.get(key);
if (obj instanceof JSONObject) {
chartOptions.put(key, fromJson((JSONObject) obj));
} else {
chartOptions.put(key, obj);
}
}
return chartOptions;
}
内容来源于网络,如有侵权,请联系作者删除!