本文整理了Java中org.codehaus.jettison.json.JSONObject.length()
方法的一些代码示例,展示了JSONObject.length()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.length()
方法的具体详情如下:
包路径:org.codehaus.jettison.json.JSONObject
类名称:JSONObject
方法名:length
[英]Get the number of keys stored in the JSONObject.
[中]获取存储在JSONObject中的键数。
代码示例来源:origin: json-path/JsonPath
@Override
public int length(Object obj)
{
if( obj instanceof org.codehaus.jettison.json.JSONArray )
{
return ((org.codehaus.jettison.json.JSONArray) obj).length();
}
if( obj instanceof org.codehaus.jettison.json.JSONObject )
{
return ((org.codehaus.jettison.json.JSONObject)obj).length();
}
if( obj instanceof String )
{
return ((String)obj).length();
}
return 0;
}
代码示例来源:origin: com.jayway.jsonpath/json-path
@Override
public int length(Object obj)
{
if( obj instanceof org.codehaus.jettison.json.JSONArray )
{
return ((org.codehaus.jettison.json.JSONArray) obj).length();
}
if( obj instanceof org.codehaus.jettison.json.JSONObject )
{
return ((org.codehaus.jettison.json.JSONObject)obj).length();
}
if( obj instanceof String )
{
return ((String)obj).length();
}
return 0;
}
代码示例来源:origin: org.codehaus.jettison/jettison
int n = length();
if (n == 0) {
return "{}";
代码示例来源:origin: org.codehaus.jettison/jettison
JSONObject jsonObject = (JSONObject)object;
if (jsonObject.length() == 1) {
String theKey = jsonObject.keys().next().toString();
if (lastKey == null || lastKey.equals(theKey)) {
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client
private Collection<Field> parseFields(JSONObject json) throws JSONException {
ArrayList<Field> res = new ArrayList<Field>(json.length());
final Iterator<String> iterator = getStringKeys(json);
while (iterator.hasNext()) {
final String key = iterator.next();
if (SPECIAL_FIELDS.contains(key)) {
continue;
}
res.add(fieldParser.parse(json.getJSONObject(key), key));
}
return res;
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-p3
private Collection<Field> parseFields(JSONObject json) throws JSONException {
ArrayList<Field> res = new ArrayList<Field>(json.length());
final Iterator<String> iterator = getStringKeys(json);
while (iterator.hasNext()) {
final String key = iterator.next();
if (SPECIAL_FIELDS.contains(key)) {
continue;
}
res.add(fieldParser.parse(json.getJSONObject(key), key));
}
return res;
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client
@Override
public Map<String, CimFieldInfo> parse(JSONObject json) throws JSONException {
final Map<String, CimFieldInfo> res = Maps.newHashMapWithExpectedSize(json.length());
final Iterator keysIterator = json.keys();
while (keysIterator.hasNext()) {
final String id = (String) keysIterator.next();
res.put(id, parseIssueFieldInfo(json.getJSONObject(id), id));
}
return res;
}
代码示例来源:origin: com.atlassian.jira/jira-rest-java-client-p3
@Override
public Map<String, CimFieldInfo> parse(JSONObject json) throws JSONException {
final Map<String, CimFieldInfo> res = Maps.newHashMapWithExpectedSize(json.length());
final Iterator keysIterator = json.keys();
while (keysIterator.hasNext()) {
final String id = (String) keysIterator.next();
res.put(id, parseIssueFieldInfo(json.getJSONObject(id), id));
}
return res;
}
代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-resourcemanager
private void verifyClusterScheduler(JSONObject json) throws JSONException,
Exception {
assertEquals("incorrect number of elements", 1, json.length());
JSONObject info = json.getJSONObject("scheduler");
assertEquals("incorrect number of elements", 1, info.length());
info = info.getJSONObject("schedulerInfo");
assertEquals("incorrect number of elements", 2, info.length());
JSONObject rootQueue = info.getJSONObject("rootQueue");
assertEquals("root", rootQueue.getString("queueName"));
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager
protected static void verifyAppTimeoutJson(ClientResponse response,
ApplicationTimeoutType type, String expireTime, long timeOutFromNow)
throws JSONException {
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString());
JSONObject jsonTimeout = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, jsonTimeout.length());
JSONObject json = jsonTimeout.getJSONObject("timeout");
verifyAppTimeoutJson(json, type, expireTime, timeOutFromNow);
}
代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-resourcemanager
protected static void
verifyAppQueueJson(ClientResponse response, String queue)
throws JSONException {
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
String responseQueue = json.getString("queue");
assertEquals(queue, responseQueue);
}
代码示例来源:origin: org.apache.hadoop/hadoop-mapreduce-client-app
public void verifyAMInfo(JSONObject info, AppContext ctx)
throws JSONException {
assertEquals("incorrect number of elements", 5, info.length());
verifyAMInfoGeneric(ctx, info.getString("appId"), info.getString("user"),
info.getString("name"), info.getLong("startedOn"),
info.getLong("elapsedTime"));
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager
private void verifyAppAttemptsInfo(JSONObject info, RMAppAttempt appAttempt,
String user)
throws Exception {
assertEquals("incorrect number of elements", 10, info.length());
verifyAppAttemptInfoGeneric(appAttempt, info.getInt("id"),
info.getLong("startTime"), info.getString("containerId"),
info.getString("nodeHttpAddress"), info.getString("nodeId"),
info.getString("logsLink"), user);
}
代码示例来源:origin: org.apache.hadoop/hadoop-mapreduce-client-app
@Test
public void testAM() throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("mapreduce")
.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
verifyAMInfo(json.getJSONObject("info"), appContext);
}
代码示例来源:origin: org.apache.hadoop/hadoop-mapreduce-client-app
@Test
public void testInfoDefault() throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("mapreduce")
.path("info/").get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
verifyAMInfo(json.getJSONObject("info"), appContext);
}
代码示例来源:origin: org.apache.hadoop/hadoop-mapreduce-client-app
@Test
public void testBlacklistedNodes() throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("mapreduce")
.path("blacklistednodes").accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
verifyBlacklistedNodesInfo(json, appContext);
}
代码示例来源:origin: org.apache.hadoop/hadoop-mapreduce-client-app
@Test
public void testInfo() throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("mapreduce")
.path("info").accept(MediaType.APPLICATION_JSON)
.get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8,
response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
verifyAMInfo(json.getJSONObject("info"), appContext);
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager
public void testSingleNodeHelper(String nodeid, RMNode nm, String media)
throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path("nodes").path(nodeid).accept(media).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
JSONObject info = json.getJSONObject("node");
verifyNodeInfo(info, nm);
}
代码示例来源:origin: org.apache.hadoop/hadoop-yarn-server-resourcemanager
public void testSingleAppsHelper(String path, RMApp app, String media)
throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path("apps").path(path).accept(media).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8,
response.getType().toString());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
verifyAppInfo(json.getJSONObject("app"), app, false);
}
代码示例来源:origin: ch.cern.hadoop/hadoop-yarn-server-resourcemanager
public void testSingleNodeHelper(String nodeid, MockNM nm, String media)
throws JSONException, Exception {
WebResource r = resource();
ClientResponse response = r.path("ws").path("v1").path("cluster")
.path("nodes").path(nodeid).accept(media).get(ClientResponse.class);
assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
JSONObject json = response.getEntity(JSONObject.class);
assertEquals("incorrect number of elements", 1, json.length());
JSONObject info = json.getJSONObject("node");
verifyNodeInfo(info, nm);
}
内容来源于网络,如有侵权,请联系作者删除!