本文整理汇总了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"));
}
示例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;
}
示例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"));
}
示例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);
}
}
}
示例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;
}
示例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());
}
示例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;
}
示例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);
}
}
}
示例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);
}
}
}
示例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()));
}
}
示例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();
}
示例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...");
}
}
}
}
示例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);
}
}
}
示例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);
}
示例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);
}
}