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


Java JSONArray.toJSONString方法代碼示例

本文整理匯總了Java中org.json.simple.JSONArray.toJSONString方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray.toJSONString方法的具體用法?Java JSONArray.toJSONString怎麽用?Java JSONArray.toJSONString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.json.simple.JSONArray的用法示例。


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

示例1: call

import org.json.simple.JSONArray; //導入方法依賴的package包/類
public Map<String, UUID> call() throws Exception {
    Map<String, UUID> uuidMap = new HashMap<String, UUID>();
    int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
    for (int i = 0; i < requests; i++) {
        HttpURLConnection connection = createConnection();
        String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
        writeBody(connection, body);
        JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream()));
        for (Object profile : array) {
            JSONObject jsonProfile = (JSONObject) profile;
            String id = (String) jsonProfile.get("id");
            String name = (String) jsonProfile.get("name");
            UUID uuid = UUIDFetcher.getUUID(id);
            uuidMap.put(name, uuid);
        }
        if (rateLimiting && i != requests - 1) {
            Thread.sleep(100L);
        }
    }
    return uuidMap;
}
 
開發者ID:k-jiang,項目名稱:BungeeAccess,代碼行數:22,代碼來源:UUIDFetcher.java

示例2: call

import org.json.simple.JSONArray; //導入方法依賴的package包/類
public Map<String, UUID> call() throws Exception {
    Map<String, UUID> uuidMap = new HashMap<>();
    int requests = (int) Math.ceil(names.size() / PROFILES_PER_REQUEST);
    for (int i = 0; i < requests; i++) {
        HttpURLConnection connection = createConnection();
        String body = JSONArray.toJSONString(names.subList(i * 100, Math.min((i + 1) * 100, names.size())));
        writeBody(connection, body);
        JSONArray array = (JSONArray) jsonParser.parse(new InputStreamReader(connection.getInputStream(), Charsets.UTF_8));
        for (Object profile : array) {
            JSONObject jsonProfile = (JSONObject) profile;
            String id = (String) jsonProfile.get("id");
            String name = (String) jsonProfile.get("name");
            UUID uuid = UUIDFetcher.getUUID(id);
            uuidMap.put(name, uuid);
        }
        if (rateLimiting && i != requests - 1) {
            Thread.sleep(100L);
        }
    }
    return uuidMap;
}
 
開發者ID:funkemunky,項目名稱:HCFCore,代碼行數:22,代碼來源:UUIDFetcher.java

示例3: updateLabel

import org.json.simple.JSONArray; //導入方法依賴的package包/類
/**
 * Update a label object
 *
 * @param label
 *            - the label to be updated. The URI, language and value of this
 *            label must be defined. The value and language code must match
 *            the values in the Ontology.
 * @param newLabelLanguage
 *            - the new language for the label
 * @param newLabelValue
 *            - the new value for the label
 * @throws OEClientException - an error has occurred contacting the server
 */
@SuppressWarnings({ "unchecked" })
public void updateLabel(Label label, String newLabelLanguage, String newLabelValue) throws OEClientException {
	logger.info("updateLabel entry: {}", label.getUri());

	if (label.getUri() == null) {
		throw new OEClientException("Attemping to update label with null URI");
	}
	String processedLabelUri = FmtUtils.stringForURI(label.getUri());
	String escapedLabelUri = getEscapedUri(processedLabelUri);

	String url = String.format("%s/%s", getModelURL(), escapedLabelUri);
	logger.info("updateLabel - URL: {}", url);
	Invocation.Builder invocationBuilder = getInvocationBuilder(url);
	JSONArray operationList = new JSONArray();
	JSONObject testOperation = new JSONObject();
	JSONObject replaceOperation = new JSONObject();

	testOperation.put("op", "test");
	testOperation.put("path", "@graph/0/skosxl:literalForm/0");
	JSONObject oldLabelObject = new JSONObject();
	oldLabelObject.put("@value", label.getValue());
	oldLabelObject.put("@language", label.getLanguageCode());
	testOperation.put("value", oldLabelObject);

	replaceOperation.put("op", "replace");
	replaceOperation.put("path", "@graph/0/skosxl:literalForm/0");
	JSONObject newLabelObject = new JSONObject();
	newLabelObject.put("@value", newLabelValue);
	newLabelObject.put("@language", newLabelLanguage);
	replaceOperation.put("value", newLabelObject);

	operationList.add(testOperation);
	operationList.add(replaceOperation);

	String conceptSchemePayload = operationList.toJSONString();

	Invocation invocation = invocationBuilder.build("PATCH",
			Entity.entity(conceptSchemePayload, "application/json-patch+json"));
	Response response = invocation.invoke();

	if (response.getStatus() == 200) {
		label.setValue(newLabelValue);
		label.setLanguage(newLabelLanguage);
		return;
	}

	throw new OEClientException(
			String.format("%s Response recieved\n%s", response.getStatus(), response.getEntity().toString()));
}
 
開發者ID:Smartlogic-Semaphore-Limited,項目名稱:Java-APIs,代碼行數:63,代碼來源:OEClientReadWrite.java


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