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


Java JSONArray類代碼示例

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


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

示例1: getAnnotatedSnippetS3

import org.codehaus.jettison.json.JSONArray; //導入依賴的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

示例2: onBulkDocs

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
public void onBulkDocs(HttpServletRequest request, final JSONArray array) {
	if (isEnabled()) {
		final InternalHttpServletRequest internalRequest = new InternalHttpServletRequest(request);
		Engine.execute(new Runnable() {

			@Override
			public void run() {
				try {
					triggerSequence(internalRequest, array);
				} catch (Exception e) {
					Engine.logBeans.error("Unable to handle 'bulkDocs' event for \""+ getName() +"\" listener", e);
				}
			}
			
		});
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:18,代碼來源:AbstractFullSyncListener.java

示例3: getEntityFeaturesJson

import org.codehaus.jettison.json.JSONArray; //導入依賴的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

示例4: getSourceSearchResultJson

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
private JSONArray getSourceSearchResultJson(
		HashMap<String, List<Triple<Integer, String, Integer>>> source,
		String query, WikipediaInterface wikiApi) throws JSONException, IOException {
	JSONArray res = new JSONArray();
	if (source.containsKey(query))
		for (Triple<Integer, String, Integer> t : source.get(query)) {
			JSONObject triple = new JSONObject();
			res.put(triple);
			triple.put("rank", t.getLeft());
			triple.put("wid", t.getRight());
			triple.put("title",
					t.getRight() >= 0 ? wikiApi.getTitlebyId(t.getRight())
							: "---not a wikipedia page---");
			triple.put("url", t.getMiddle());
		}
	return res;
}
 
開發者ID:marcocor,項目名稱:smaph,代碼行數:18,代碼來源:SmaphDebugger.java

示例5: getResultsJson

import org.codehaus.jettison.json.JSONArray; //導入依賴的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

示例6: sandbox

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
/**
 * 獲取沙箱信息.
 * 
 * @param appName 作業雲配置App的名字
 * @return 沙箱信息
 * @throws JSONException 解析JSON格式異常
 */
public JsonArray sandbox(final String appName) throws JSONException {
    JSONObject state = fetch(stateUrl);
    JsonArray result = new JsonArray();
    for (JSONObject each : findExecutors(state.getJSONArray("frameworks"), appName)) {
        JSONArray slaves = state.getJSONArray("slaves");
        String slaveHost = null;
        for (int i = 0; i < slaves.length(); i++) {
            JSONObject slave = slaves.getJSONObject(i);
            if (each.getString("slave_id").equals(slave.getString("id"))) {
                slaveHost = slave.getString("pid").split("@")[1];
            }
        }
        Preconditions.checkNotNull(slaveHost);
        JSONObject slaveState = fetch(String.format("http://%s/state", slaveHost));
        String workDir = slaveState.getJSONObject("flags").getString("work_dir");
        Collection<JSONObject> executorsOnSlave = findExecutors(slaveState.getJSONArray("frameworks"), appName);
        for (JSONObject executorOnSlave : executorsOnSlave) {
            JsonObject r = new JsonObject();
            r.addProperty("hostname", slaveState.getString("hostname"));
            r.addProperty("path", executorOnSlave.getString("directory").replace(workDir, ""));
            result.add(r);
        }
    }
    return result;
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:33,代碼來源:MesosStateService.java

示例7: findExecutors

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
private Collection<JSONObject> findExecutors(final JSONArray frameworks, final String appName) throws JSONException {
    List<JSONObject> result = Lists.newArrayList();
    Optional<String> frameworkIDOptional = frameworkIDService.fetch();
    String frameworkID;
    if (frameworkIDOptional.isPresent()) {
        frameworkID = frameworkIDOptional.get();
    } else {
        return result;
    }
    for (int i = 0; i < frameworks.length(); i++) {
        JSONObject framework = frameworks.getJSONObject(i);
        if (!framework.getString("id").equals(frameworkID)) {
            continue;
        }
        JSONArray executors = framework.getJSONArray("executors");
        for (int j = 0; j < executors.length(); j++) {
            JSONObject executor = executors.getJSONObject(j);
            if (null == appName || appName.equals(getExecutorId(executor).split("@[email protected]")[0])) {
                result.add(executor);
            }
        }
    }
    return result;
}
 
開發者ID:elasticjob,項目名稱:elastic-job-cloud,代碼行數:25,代碼來源:MesosStateService.java

示例8: listFiles

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
public void listFiles(JSONObject response) throws JSONException, IOException {
	File canonicalDir = destDir.getCanonicalFile();
	int uriDirectoryLength = canonicalDir.toURI().toString().length();
	JSONArray jArray = new JSONArray();
	
	for (File f : FileUtils.listFiles(canonicalDir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE)) {
		File canonnicalF = f.getCanonicalFile();
		JSONObject jObj = new JSONObject();
		jObj.put("uri", URLDecoder.decode(canonnicalF.toURI().toString().substring(uriDirectoryLength), "UTF-8"));
		jObj.put("date", canonnicalF.lastModified());
		jObj.put("size", canonnicalF.length());
		jArray.put(jObj);
	}
	response.put("files", jArray);
	response.put("date", destDir.lastModified());
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:17,代碼來源:MobileResourceHelper.java

示例9: exportUsers

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
public JSONObject exportUsers(JSONArray usernames) throws EngineException {
	try {
		JSONObject users;
		JSONObject export = new JSONObject();
		
		synchronized (this) {
			users = load();
		}

		for (int i = 0; i < usernames.length(); i++) {
			String name = usernames.getJSONObject(i).getString("name");
			if (users.has(name)) {
				export.put(name, users.get(name));
			}
		}
		return export;
	} catch (Exception exception) {
		throw new EngineException("Failed to update Users", exception);
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:21,代碼來源:AuthenticatedSessionManager.java

示例10: IonProperty

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
public IonProperty() {
	try {
		jsonProperty = new JSONObject()
			.put(Key.name.name(), "property")
			.put(Key.attr.name(), "")
			.put(Key.label.name(), "label")
			.put(Key.editor.name(), "")
			.put(Key.hidden.name(), false)
			.put(Key.composite.name(), false)
			.put(Key.description.name(), "description")
			.put(Key.category.name(), "Attributes")
			.put(Key.mode.name(), "plain")
			.put(Key.type.name(), "string")
			.put(Key.value.name(), false)
			.put(Key.values.name(), new JSONArray().put(false).put(true));
	} catch (JSONException e) {
		e.printStackTrace();
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:20,代碼來源:IonProperty.java

示例11: getCfgPlugins

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
protected Map<String, String> getCfgPlugins(Key key, String keyId) {
	try {
		Map<String, String> map = new HashMap<String, String>();
		JSONArray ar = jsonConfig.getJSONArray(key.name());
		for (int i=0; i<ar.length(); i++) {
			Object ob = ar.get(i);
			if (ob instanceof JSONObject) {
				JSONObject jsonImport = (JSONObject)ob;
				String plugin = jsonImport.getString(keyId);
				if (!plugin.isEmpty() && !jsonImport.toString().isEmpty()) {
					map.put(plugin, jsonImport.toString());
				}
			}
		}
		return map;
	} catch (JSONException e) {
		return new HashMap<String, String>();
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:20,代碼來源:IonConfig.java

示例12: getCfgImports

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
protected Map<String, String> getCfgImports(Key key, String key1, String key2) {
	try {
		Map<String, String> map = new HashMap<String, String>();
		JSONArray ar = jsonConfig.getJSONArray(key.name());
		for (int i=0; i<ar.length(); i++) {
			Object ob = ar.get(i);
			if (ob instanceof JSONObject) {
				JSONObject jsonImport = (JSONObject)ob;
				String val1 = jsonImport.getString(key1);
				String val2 = jsonImport.getString(key2);
				if (!val1.isEmpty() && !val2.isEmpty()) {
					map.put(val1, val2);
				}
			}
		}
		return map;
	} catch (JSONException e) {
		return new HashMap<String, String>();
	}
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:21,代碼來源:IonConfig.java

示例13: read

import org.codehaus.jettison.json.JSONArray; //導入依賴的package包/類
private Map<Long, Toll> read(String tollsFile) {
    try {
        Map<Long, Toll> tolls = newHashMap();

        File file = new File(tollsFile);

        if (file.exists()) {
            JSONArray array = new JSONArray(IOUtils.toString(file.toURI(), UTF_8));
            for (int i = 0; i < array.length(); i++) {
                JSONObject json = array.getJSONObject(i);
                tolls.put(json.getLong("tomtomId"), new Toll(json.getInt("id"), json.getString("name"), json.getString("tollcode1"), json.optString("tollcode2")));
            }

            log.info("Loaded {} tolls", tolls.size());

        } else {
            log.info("File not found : {}", file.getAbsolutePath());
        }

        return tolls;
    }
    catch (IOException|JSONException e) {
        throw propagate(e);
    }
}
 
開發者ID:Mappy,項目名稱:fpm,代碼行數:26,代碼來源:TollReader.java

示例14: testNodeAppsUser

import org.codehaus.jettison.json.JSONArray; //導入依賴的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: testNodeAppsState

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

  ClientResponse response = r.path("ws").path("v1").path("node").path("apps")
      .queryParam("state", ApplicationState.RUNNING.toString())
      .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), app2, hash2);

}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:TestNMWebServicesApps.java


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