本文整理了Java中org.json.JSONObject.length()
方法的一些代码示例,展示了JSONObject.length()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.length()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:length
[英]Returns the number of name/value mappings in this object.
[中]返回此对象中的名称/值映射数。
代码示例来源:origin: commonsguy/cw-omnibus
@Override
public int getGroupCount() {
return(model.length());
}
代码示例来源:origin: apache/geode
/**
* @return the column size of this GfJsonObject
*/
public int size() {
return jsonObject.length();
}
代码示例来源:origin: google/physical-web
/**
* Create a JSON object that represents this data structure.
* @return a JSON serialization of this data structure.
*/
public JSONObject jsonSerialize() {
JSONObject jsonObject = new JSONObject();
jsonObject.put(ID_KEY, mId);
jsonObject.put(URL_KEY, mUrl);
if (mExtraData.length() > 0) {
jsonObject.put(EXTRA_KEY, mExtraData);
}
return jsonObject;
}
代码示例来源:origin: zzz40500/GsonFormat
/**
* Get an array of field names from a JSONObject.
*
* @return An array of field names, or null if there are no names.
*/
public static String[] getNames(JSONObject jo) {
int length = jo.length();
if (length == 0) {
return null;
}
Iterator<String> iterator = jo.keys();
String[] names = new String[length];
int i = 0;
while (iterator.hasNext()) {
names[i] = iterator.next();
i += 1;
}
return names;
}
代码示例来源:origin: ACRA/acra
@NonNull
public Map<String, Object> toMap() {
final Map<String, Object> map = new HashMap<>(content.length());
for (final Iterator<String> iterator = content.keys(); iterator.hasNext(); ) {
final String key = iterator.next();
map.put(key, get(key));
}
return map;
}
}
代码示例来源:origin: google/physical-web
/**
* Create a JSON object that represents this data structure.
* @return a JSON serialization of this data structure.
*/
public JSONObject jsonSerialize() {
JSONObject jsonObject = new JSONObject();
jsonObject.put(REQUESTURL_KEY, mRequestUrl);
jsonObject.put(SITEURL_KEY, mSiteUrl);
if (mTitle != null) {
jsonObject.put(TITLE_KEY, mTitle);
}
if (mDescription != null) {
jsonObject.put(DESCRIPTION_KEY, mDescription);
}
if (mIconUrl != null) {
jsonObject.put(ICONURL_KEY, mIconUrl);
}
if (mGroupId != null) {
jsonObject.put(GROUPID_KEY, mGroupId);
}
if (mExtraData.length() > 0) {
jsonObject.put(EXTRA_KEY, mExtraData);
}
return jsonObject;
}
代码示例来源:origin: loklak/loklak_server
/**
* Get an array of field names from a JSONObject.
*
* @return An array of field names, or null if there are no names.
*/
public static String[] getNames(JSONObject jo) {
int length = jo.length();
if (length == 0) {
return null;
}
return jo.keySet().toArray(new String[length]);
}
代码示例来源:origin: RipMeApp/ripme
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<>();
for (Element script : doc.select("script")) {
if (script.data().contains("var images = ")) {
String s = script.data();
s = s.replaceAll("var seriesId = \\d+;", "");
s = s.replaceAll("var chapterId = \\d+;", "");
s = s.replaceAll("var pages = \\d+;", "");
s = s.replaceAll("var page = \\d+;", "");
s = s.replaceAll("var prevCha = null;", "");
s = s.replaceAll("var nextCha = \\.*;", "");
String json = s.replaceAll("var images = ", "").replaceAll(";", "");
JSONObject images = new JSONObject(json);
for (int i = 1; i < images.length() +1; i++) {
result.add(images.getString(Integer.toString(i)));
}
}
}
return result;
}
代码示例来源:origin: json-path/JsonPath
@Override
public int length(Object obj) {
if (isArray(obj)) {
return toJsonArray(obj).length();
} else if (isMap(obj)) {
return toJsonObject(obj).length();
} else {
if (obj instanceof String) {
return ((String) obj).length();
}
}
throw new JsonPathException("length operation can not applied to " + obj != null ? obj.getClass().getName() : "null");
}
代码示例来源:origin: loklak/loklak_server
/**
* cleanup deletes all old entries and frees up the memory.
* some outside process muss call this frequently
* @return self
*/
public Accounting cleanup() {
if (!this.has("requests")) return this;
JSONObject requests = this.getJSONObject("requests");
for (String path: requests.keySet()) {
JSONObject events = requests.getJSONObject(path);
// shrink that map and delete everything which is older than now minus one hour
long pivotTime = System.currentTimeMillis() - ONE_HOUR_MILLIS;
while (events.length() > 0 && Long.parseLong(events.keys().next()) < pivotTime) events.remove(events.keys().next());
if (events.length() == 0) requests.remove(path);
}
return this;
}
代码示例来源:origin: apache/hive
public void extractStagesAndPlans(JSONObject inputObject) throws Exception {
// extract stages
JSONObject dependency = inputObject.getJSONObject("STAGE DEPENDENCIES");
if (dependency != null && dependency.length() > 0) {
// iterate for the first time to get all the names of stages.
for (String stageName : JSONObject.getNames(dependency)) {
this.stages.put(stageName, new Stage(stageName, this));
}
// iterate for the second time to get all the dependency.
for (String stageName : JSONObject.getNames(dependency)) {
JSONObject dependentStageNames = dependency.getJSONObject(stageName);
this.stages.get(stageName).addDependency(dependentStageNames, this.stages);
}
}
// extract stage plans
JSONObject stagePlans = inputObject.getJSONObject("STAGE PLANS");
if (stagePlans != null && stagePlans.length() > 0) {
for (String stageName : JSONObject.getNames(stagePlans)) {
JSONObject stagePlan = stagePlans.getJSONObject(stageName);
this.stages.get(stageName).extractVertex(stagePlan);
}
}
}
代码示例来源:origin: facebook/facebook-android-sdk
if (data.length() > 0) {
newJsonObject.put("data", data);
代码示例来源:origin: apache/hive
Map<String, String> attrs = new TreeMap<>();
Vertex v = null;
if (opObj.length() > 0) {
String[] names = JSONObject.getNames(opObj);
for (String name : names) {
} else if (o instanceof JSONObject) {
JSONObject attrObj = (JSONObject) o;
if (attrObj.length() > 0) {
if (name.equals("Processor Tree:")) {
JSONObject object = new JSONObject(new LinkedHashMap<>());
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testJsonObjectPutAll() throws JSONException {
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("hello", "world");
map.put("hocus", "pocus");
JSONObject jsonObject = new JSONObject();
JsonUtil.jsonObjectPutAll(jsonObject, map);
assertEquals("pocus", jsonObject.get("hocus"));
assertEquals(2, jsonObject.length());
}
代码示例来源:origin: facebook/facebook-android-sdk
@Test
public void testJsonObjectClear() throws JSONException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("hello", "world");
jsonObject.put("hocus", "pocus");
JsonUtil.jsonObjectClear(jsonObject);
assertEquals(0, jsonObject.length());
}
代码示例来源:origin: loklak/loklak_server
@Override
public JSONObject[] service(Query call, Authorization rights) throws APIException {
// make call to the embedded api
if (this.serverProtocolHostStub == null) return new JSONObject[]{serviceImpl(call, null, rights, rights.getPermissions(this))};
// make call(s) to a remote api(s)
JSONObject[] results = new JSONObject[this.serverProtocolHostStub.length];
for (int rc = 0; rc < results.length; rc++) {
try {
StringBuilder urlquery = new StringBuilder();
for (String key: call.getKeys()) {
urlquery.append(urlquery.length() == 0 ? '?' : '&').append(key).append('=').append(call.get(key, ""));
}
String urlstring = this.serverProtocolHostStub[rc] + this.getAPIPath() + urlquery.toString();
byte[] jsonb = ClientConnection.download(urlstring);
if (jsonb == null || jsonb.length == 0) throw new IOException("empty content from " + urlstring);
String jsons = UTF8.String(jsonb);
JSONObject json = new JSONObject(jsons);
if (json == null || json.length() == 0) {
results[rc] = null;
continue;
};
results[rc] = json;
} catch (Throwable e) {
DAO.severe(e);
}
}
return results;
}
代码示例来源:origin: ankidroid/Anki-Android
@Override
public void onRemoveSearch(String searchName) {
Timber.d("OnRemoveSelection using search named: %s", searchName);
try {
JSONObject savedFiltersObj = getCol().getConf().optJSONObject("savedFilters");
if (savedFiltersObj != null && savedFiltersObj.has(searchName)) {
savedFiltersObj.remove(searchName);
getCol().getConf().put("savedFilters", savedFiltersObj);
getCol().flush();
if (savedFiltersObj.length() == 0) {
mMySearchesItem.setVisible(false);
}
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: cloudfoundry/uaa
@Override
public boolean matches(Object item) {
if(!String.class.isInstance(item)){
return false;
}
if(this.expected == null && "null".equals(item)){
return true;
}
JSONObject actual = null;
try {
actual = new JSONObject(new JSONTokener(item.toString()));
} catch (JSONException e) {
return false;
}
if(this.expected.length() != actual.length()) {
return false;
}
JSONArray names = actual.names();
for(int i = 0, len = names.length(); i < len; i++){
try {
String name = names.getString(i);
if(!Objects.equals(expected.get(name), actual.get(name))){
return false;
}
} catch (JSONException e) {
return false;
}
}
return true;
}
代码示例来源:origin: apache/hive
plan.getOptimizedQueryString());
if (jsonPlan.getJSONObject(ExplainTask.STAGE_DEPENDENCIES) != null &&
jsonPlan.getJSONObject(ExplainTask.STAGE_DEPENDENCIES).length() <=
conf.getIntVar(ConfVars.HIVE_SERVER2_WEBUI_MAX_GRAPH_SIZE)) {
ret = jsonPlan.toString();
代码示例来源:origin: loklak/loklak_server
public static JSONObject getUser(String screen_name, boolean forceReload) throws TwitterException, IOException {
if (!forceReload) {
JsonFactory mapcapsule = DAO.user_dump.get("screen_name",screen_name);
if (mapcapsule == null) mapcapsule = DAO.user_dump.get("id_str", screen_name);
if (mapcapsule != null) {
JSONObject json = mapcapsule.getJSON();
if (json.length() > 0) {
// check if the entry is maybe outdated, i.e. if it is empty or too old
try {
Date d = DAO.user_dump.parseDate(json);
if (d.getTime() + DateParser.DAY_MILLIS > System.currentTimeMillis()) return json;
} catch (ParseException e) {
return json;
}
}
}
}
TwitterFactory tf = getUserTwitterFactory(screen_name);
if (tf == null) tf = getAppTwitterFactory();
if (tf == null) return new JSONObject();
Twitter twitter = tf.getInstance();
User user = twitter.showUser(screen_name);
RateLimitStatus rateLimitStatus = user.getRateLimitStatus();
getUserResetTime = System.currentTimeMillis() + rateLimitStatus.getSecondsUntilReset() * 1000;
getUserRemaining = rateLimitStatus.getRemaining();
JSONObject json = user2json(user);
enrichLocation(json);
DAO.user_dump.putUnique(json);
return json;
}
内容来源于网络,如有侵权,请联系作者删除!