当前位置: 首页>>代码示例>>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;未经允许,请勿转载。