當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject類代碼示例

本文整理匯總了Java中org.codehaus.jettison.json.JSONObject的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject類的具體用法?Java JSONObject怎麽用?Java JSONObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JSONObject類屬於org.codehaus.jettison.json包,在下文中一共展示了JSONObject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: verifyClusterMetricsJSON

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
public void verifyClusterMetricsJSON(JSONObject json) throws JSONException,
    Exception {
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject clusterinfo = json.getJSONObject("clusterMetrics");
  assertEquals("incorrect number of elements", 27, clusterinfo.length());
  verifyClusterMetrics(
      clusterinfo.getInt("appsSubmitted"), clusterinfo.getInt("appsCompleted"),
      clusterinfo.getInt("reservedMB"), clusterinfo.getInt("availableMB"),
      clusterinfo.getInt("allocatedMB"),
      clusterinfo.getInt("reservedVirtualCores"), clusterinfo.getInt("availableVirtualCores"),
      clusterinfo.getInt("allocatedVirtualCores"), clusterinfo.getInt("totalVirtualCores"),
      clusterinfo.getInt("reservedGpuCores"), clusterinfo.getInt("availableGpuCores"),
      clusterinfo.getInt("allocatedGpuCores"), clusterinfo.getInt("totalGpuCores"),
      clusterinfo.getInt("containersAllocated"),
      clusterinfo.getInt("totalMB"), clusterinfo.getInt("totalNodes"),
      clusterinfo.getInt("lostNodes"), clusterinfo.getInt("unhealthyNodes"),
      clusterinfo.getInt("decommissionedNodes"),
      clusterinfo.getInt("rebootedNodes"),clusterinfo.getInt("activeNodes"));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestRMWebServices.java

示例2: getAnnotatedSnippetS3

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
private JSONArray getAnnotatedSnippetS3(String query, WikipediaInterface wikiApi) throws JSONException, IOException {
	JSONArray res = new JSONArray();
	if (this.annotatedSnippetsAndBoldsS3.containsKey(query))
		for (Triple<String, HashSet<Annotation>, HashSet<Mention>> p : this.annotatedSnippetsAndBoldsS3.get(query)) {
			JSONObject pairJs = new JSONObject();
			res.put(pairJs);
			pairJs.put("snippet", p.getLeft());
			JSONArray annotationsJs = new JSONArray();
			pairJs.put("parts", annotationsJs);
			int lastIdx = 0;
			for (Annotation a : SmaphUtils.sorted(p.getMiddle())) {
				annotationsJs.put(getTextPartJson(p.getLeft(), lastIdx, a.getPosition(), p.getRight()));

				JSONObject annotationJs = getTextPartJson(p.getLeft(), a.getPosition(), a.getPosition() + a.getLength(),
						p.getRight());
				annotationsJs.put(annotationJs);
				annotationJs.put("title", wikiApi.getTitlebyId(a.getConcept()));
				annotationJs.put("wid", a.getConcept());
				annotationJs.put("url", widToUrl(a.getConcept(), wikiApi));
				lastIdx = a.getPosition() + a.getLength();
			}
			annotationsJs.put(getTextPartJson(p.getLeft(), lastIdx, p.getLeft().length(), p.getRight()));
		}
	return res;
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:26,代碼來源:SmaphDebugger.java

示例3: testNodeAppsUserNone

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
@Test
public void testNodeAppsUserNone() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  addAppContainers(app);
  Application app2 = new MockApp("foo", 1234, 2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  ClientResponse response = r.path("ws").path("v1").path("node").path("apps")
      .queryParam("user", "george").accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestNMWebServicesApps.java

示例4: verifyHsJobTaskAttemptCounters

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
public void verifyHsJobTaskAttemptCounters(JSONObject info, TaskAttempt att)
    throws JSONException {

  assertEquals("incorrect number of elements", 2, info.length());

  WebServicesTestUtils.checkStringMatch("id", MRApps.toString(att.getID()),
      info.getString("id"));

  // just do simple verification of fields - not data is correct
  // in the fields
  JSONArray counterGroups = info.getJSONArray("taskAttemptCounterGroup");
  for (int i = 0; i < counterGroups.length(); i++) {
    JSONObject counterGroup = counterGroups.getJSONObject(i);
    String name = counterGroup.getString("counterGroupName");
    assertTrue("name not set", (name != null && !name.isEmpty()));
    JSONArray counters = counterGroup.getJSONArray("counter");
    for (int j = 0; j < counters.length(); j++) {
      JSONObject counter = counters.getJSONObject(j);
      String counterName = counter.getString("name");
      assertTrue("name not set",
          (counterName != null && !counterName.isEmpty()));
      long value = counter.getLong("value");
      assertTrue("value  >= 0", value >= 0);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:TestHsWebServicesAttempts.java

示例5: getEntityFeaturesJson

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
private JSONArray getEntityFeaturesJson(
		HashMap<String, List<Triple<Integer, HashMap<String, Double>, Boolean>>> source,
		String query, WikipediaInterface wikiApi) throws JSONException,
		IOException {
	JSONArray res = new JSONArray();
	if (source.containsKey(query))
		for (Triple<Integer, HashMap<String, Double>, Boolean> p : source
				.get(query)) {
			JSONObject pairJs = new JSONObject();
			res.put(pairJs);
			pairJs.put("wid", p.getLeft());
			pairJs.put("title", wikiApi.getTitlebyId(p.getLeft()));
			pairJs.put("url", widToUrl(p.getLeft(), wikiApi));
			JSONObject features = new JSONObject();
			pairJs.put("features", features);
			for (String ftrName : SmaphUtils.sorted(p.getMiddle().keySet()))
				features.put(ftrName, p.getMiddle().get(ftrName));
			pairJs.put("accepted", p.getRight());
		}
	return res;
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:22,代碼來源:SmaphDebugger.java

示例6: testJobsQueryStartTimeEnd

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
@Test
public void testJobsQueryStartTimeEnd() throws JSONException, Exception {
  WebResource r = resource();
  // the mockJobs start time is the current time - some random amount
  Long now = System.currentTimeMillis();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("startedTimeEnd", String.valueOf(now))
      .accept(MediaType.APPLICATION_JSON).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 jobs = json.getJSONObject("jobs");
  JSONArray arr = jobs.getJSONArray("job");
  assertEquals("incorrect number of elements", 3, arr.length());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestHsWebServicesJobsQuery.java

示例7: getResultsJson

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
private JSONArray getResultsJson(String query, WikipediaInterface wikiApi)
		throws JSONException, IOException {
	JSONArray res = new JSONArray();
	if (result.containsKey(query))
		for (ScoredAnnotation a: result.get(query)) {
			JSONObject triple = new JSONObject();
			res.put(triple);
			triple.put("begin", a.getPosition());
			triple.put("end", a.getPosition() + a.getLength());
			triple.put("score", a.getScore());
			triple.put("wid", a.getConcept());
			triple.put("title", wikiApi.getTitlebyId(a.getConcept()));
			triple.put("url", widToUrl(a.getConcept(), wikiApi));
		}
	return res;
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:17,代碼來源:SmaphDebugger.java

示例8: verifyHsTask

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
public void verifyHsTask(JSONArray arr, Job job, String type)
    throws JSONException {
  for (Task task : job.getTasks().values()) {
    TaskId id = task.getID();
    String tid = MRApps.toString(id);
    Boolean found = false;
    if (type != null && task.getType() == MRApps.taskType(type)) {

      for (int i = 0; i < arr.length(); i++) {
        JSONObject info = arr.getJSONObject(i);
        if (tid.matches(info.getString("id"))) {
          found = true;
          verifyHsSingleTask(info, task);
        }
      }
      assertTrue("task with id: " + tid + " not in web service output", found);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestHsWebServicesTasks.java

示例9: testTaskAttemptsSlash

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
@Test
public void testTaskAttemptsSlash() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    for (Task task : jobsMap.get(id).getTasks().values()) {

      String tid = MRApps.toString(task.getID());
      ClientResponse response = r.path("ws").path("v1").path("history")
          .path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid)
          .path("attempts/").accept(MediaType.APPLICATION_JSON)
          .get(ClientResponse.class);
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject json = response.getEntity(JSONObject.class);
      verifyHsTaskAttempts(json, task);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestHsWebServicesAttempts.java

示例10: verifyHsJobConf

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
public void verifyHsJobConf(JSONObject info, Job job) throws JSONException {

    assertEquals("incorrect number of elements", 2, info.length());

    WebServicesTestUtils.checkStringMatch("path", job.getConfFile().toString(),
        info.getString("path"));
    // just do simple verification of fields - not data is correct
    // in the fields
    JSONArray properties = info.getJSONArray("property");
    for (int i = 0; i < properties.length(); i++) {
      JSONObject prop = properties.getJSONObject(i);
      String name = prop.getString("name");
      String value = prop.getString("value");
      assertTrue("name not set", (name != null && !name.isEmpty()));
      assertTrue("value not set", (value != null && !value.isEmpty()));
    }
  }
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestHsWebServicesJobConf.java

示例11: DesignDocumentTreeObject

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
public DesignDocumentTreeObject(Viewer viewer, DatabaseObject object, boolean inherited) {
	super(viewer, object, inherited);
	fFilters = new FolderTreeObject(viewer, "Filters");
	fUpdates = new FolderTreeObject(viewer, "Updates");
	fViews = new FolderTreeObject(viewer, "Views");
	loadFilters();
	loadUpdates();
	loadViews();
	
	if (object.bNew) {
		JSONObject json = getObject().getJSONObject();
		CouchKey._id.put(json, CouchKey._design.key() + getObject().getName());
		CouchKey._rev.remove(json);
	}
	
	syncDocument();
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:18,代碼來源:DesignDocumentTreeObject.java

示例12: loadFilters

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
private void loadFilters() {
	JSONObject jsonDocument = getObject().getJSONObject();
	JSONObject filters = CouchKey.filters.JSONObject(jsonDocument);
	
	if (filters != null) {
		if (filters.length() > 0) {
			addChild(fFilters);
		}
		
		for (Iterator<String> i = GenericUtils.cast(filters.keys()); i.hasNext(); ) {
			String key = i.next();
			
			try {
				FilterObject filter = new FilterObject(key, filters.getString(key));
				fFilters.addChild(new DesignDocumentFilterTreeObject(viewer, filter));
			} catch (Exception e) {
				Engine.logBeans.warn("[DesignDocument] filter named '" + key + "' is null; skipping...");
			}
		}
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-eclipse,代碼行數:22,代碼來源:DesignDocumentTreeObject.java

示例13: testTaskAttemptsDefault

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
@Test
public void testTaskAttemptsDefault() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    for (Task task : jobsMap.get(id).getTasks().values()) {

      String tid = MRApps.toString(task.getID());
      ClientResponse response = r.path("ws").path("v1").path("mapreduce")
          .path("jobs").path(jobId).path("tasks").path(tid).path("attempts")
          .get(ClientResponse.class);
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject json = response.getEntity(JSONObject.class);
      verifyAMTaskAttempts(json, task);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestAMWebServicesAttempts.java

示例14: testNodeAppsUser

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
@Test
public void testNodeAppsUser() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  HashMap<String, String> hash = addAppContainers(app);
  Application app2 = new MockApp("foo", 1234, 2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  ClientResponse response = r.path("ws").path("v1").path("node").path("apps")
      .queryParam("user", "mockUser").accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);

  JSONObject info = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, info.length());
  JSONArray appInfo = info.getJSONArray("app");
  assertEquals("incorrect number of elements", 1, appInfo.length());
  verifyNodeAppInfo(appInfo.getJSONObject(0), app, hash);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestNMWebServicesApps.java

示例15: testTasks

import org.codehaus.jettison.json.JSONObject; //導入依賴的package包/類
@Test
public void testTasks() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    ClientResponse response = r.path("ws").path("v1").path("mapreduce")
        .path("jobs").path(jobId).path("tasks")
        .accept(MediaType.APPLICATION_JSON).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 tasks = json.getJSONObject("tasks");
    JSONArray arr = tasks.getJSONArray("task");
    assertEquals("incorrect number of elements", 2, arr.length());

    verifyAMTask(arr, jobsMap.get(id), null);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:TestAMWebServicesTasks.java


注:本文中的org.codehaus.jettison.json.JSONObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。