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


Java JSONValue.toJSONString方法代碼示例

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


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

示例1: handleRequest

import org.json.simple.JSONValue; //導入方法依賴的package包/類
String handleRequest(JsonRequest request) throws Exception
   {
String output = "";
	
String file = request.getString("path", "/");
JSONObject o = new JSONObject();
try {
    this.source.addSource(file);
    o.put("status", "OK");

} catch (Exception e) {
    o.put("status", "ERR");
    o.put("error",  e.toString());
}

return JSONValue.toJSONString(o);
   }
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:18,代碼來源:FileLoader.java

示例2: postPlugin

import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
 * 發送服務器數據到統計網頁
 */
private void postPlugin() throws IOException {
    // 服務器數據獲取
    final String pluginname = Uranium.name;
    final String tmposarch = System.getProperty("os.arch");

    final Map<String, Object> data = new HashMap();
    data.put("guid", guid);
    data.put("server_version", Bukkit.getVersion());
    data.put("server_port", Bukkit.getServer().getPort());
    data.put("server_tps", FMLCommonHandler.instance().getMinecraftServerInstance().recentTps[1]);
    data.put("plugin_version", Uranium.getCurrentVersion());
    data.put("players_online", Bukkit.getServer().getOnlinePlayers().size());
    data.put("os_name", System.getProperty("os.name"));
    data.put("os_arch", tmposarch.equalsIgnoreCase("amd64") ? "x86_64" : tmposarch);
    data.put("os_version", System.getProperty("os.version"));
    data.put("os_usemem", (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024);
    data.put("os_cores", Runtime.getRuntime().availableProcessors());
    data.put("auth_mode", Bukkit.getServer().getOnlineMode() ? 1 : 0);
    data.put("java_version", System.getProperty("java.version"));

    final String jsondata = "Info=" + JSONValue.toJSONString(data);

    final String url = String.format("http://api.yumc.pw/I/P/S/V/%s/P/%s", REVISION, URLEncoder.encode(pluginname, "UTF-8"));
    print("Plugin: " + pluginname + " Send Data To CityCraft Data Center");
    print("Address: " + url);
    print("Data: " + jsondata);
    // 發送數據
    final JSONObject result = (JSONObject) JSONValue.parse(postData(url, jsondata));
    print("Plugin: " + pluginname + " Recover Data From CityCraft Data Center: " + result.get("info"));
}
 
開發者ID:UraniumMC,項目名稱:Uranium,代碼行數:34,代碼來源:YUMCStatistics.java

示例3: getPortResponseBasedOnSwitchId

import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
 * get All Ports.
 *
 * @param switchId
 *            the switch id
 * @return List<PortInfo>
 */
public List<PortInfo> getPortResponseBasedOnSwitchId(String switchId) {

	log.info("Inside ServiceSwitchImpl method getPortResponseBasedOnSwitchId");
	List<PortInfo> switchPortsInfoList = new ArrayList<PortInfo>();
	ObjectMapper mapper = new ObjectMapper();
	String key = switchId;
	try {
		JSONObject jsonObject = switchIntegrationService.getSwitchPorts();
		log.info("getPortResponseBasedOnSwitchId GET_SWITCH_PORT_DATA_URL api call response is "
				+ jsonObject);

		if (jsonObject != null) {
			Object object = jsonObject.get(key);
			if (object != null) {
				String val = JSONValue.toJSONString(object);
				PortDetailResponse portDetailResponse = mapper.readValue(
						val, PortDetailResponse.class);

				List<PortDesc> portDescList = portDetailResponse
						.getPortDesc();
				if (portDescList != null && !portDescList.isEmpty()) {
					switchPortsInfoList = switchDataUtil.getSwitchPortInfo(
							portDescList, key, switchPortsInfoList);
				}
			}
		}
	} catch (Exception exception) {
		log.error("Exception in getPortResponseBasedOnSwitchId "
				+ exception.getMessage());
	}

	log.info("exit ServiceSwitchImpl method getPortResponseBasedOnSwitchId");
	return switchPortsInfoList;
}
 
開發者ID:telstra,項目名稱:open-kilda,代碼行數:42,代碼來源:ServiceSwitchImpl.java

示例4: toString

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public static String toString(Map<String, String> properties,
		boolean useOldVersion) {
	if (useOldVersion) {
		final StringBuilder sb = new StringBuilder();
		final Iterator<Entry<String, String>> iterator = properties
				.entrySet().iterator();
		while (iterator.hasNext()) {
			final Entry<String, String> property = iterator.next();
			sb.append(property.getKey());
			sb.append(OLD_KEY_VALUE_SEPARATOR);
			sb.append(property.getValue());
			if (iterator.hasNext()) {
				sb.append(OLD_PROPERTY_SEPARATOR_CHAR);
			}
		}
		return sb.toString();
	} else {
		return JSON_PREFIX + JSONValue.toJSONString(properties);
	}
}
 
開發者ID:clic-lab,項目名稱:spf,代碼行數:21,代碼來源:Properties.java

示例5: handleRequest

import org.json.simple.JSONValue; //導入方法依賴的package包/類
String handleRequest(JsonRequest request) throws Exception {
String output = "";

long starttime = 0;
long endtime = 0;
long period = 0;

starttime = request.getNumber("start", 0);
endtime = request.getNumber("end", 0);
period = request.getNumber("period", 0);

if (starttime == 0) { starttime = source.getStartTime(); }
if (endtime == 0) { 
    if (period > 0) {
	endtime = starttime + period;
    } else {
	endtime = source.getEndTime(); 
    }
}

LogIterator iter = source.iterator(starttime, endtime);
JSONObject data = new JSONObject();
data.put("startTime", starttime);
data.put("endTime", endtime);
long size = 0;

size = iter.size();

data.put("numEntries",  size);
if (LOG.isDebugEnabled()) {
    LOG.debug("handle(start= " + starttime + ", end=" + endtime + ", numEntries=" + size +")");
}
iter.close();
return JSONValue.toJSONString(data);
   }
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:36,代碼來源:NumEvents.java

示例6: handleRequest

import org.json.simple.JSONValue; //導入方法依賴的package包/類
String handleRequest(JsonRequest request) throws Exception
   {
String output = "";
JSONArray filelist = new JSONArray();

File base = new File(request.getString("path", "/"));
if (!base.exists() || !base.isDirectory()) {
    throw new FileNotFoundException("Couldn't find [" + request + "]");
}
File[] files = base.listFiles();
Arrays.sort(files, new Comparator<File>() { 
	public int compare(File o1, File o2) {
	    if (o1.isDirectory() != o2.isDirectory()) {
		if (o1.isDirectory()) {
		    return -1;
		} else {
		    return 1;
		}
	    }
	    return o1.getName().compareToIgnoreCase(o2.getName());
	} 
    });

for (File f : files) {
    JSONObject o = new JSONObject();
    o.put("file", f.getName());
    o.put("type", f.isDirectory() ? "D" : "F");
    o.put("path", f.getCanonicalPath());
    filelist.add(o);
}
return JSONValue.toJSONString(filelist);
   }
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:33,代碼來源:Fs.java

示例7: taskStatusToString

import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
 * Pretty-print mesos protobuf TaskStatus.
 */
public static String taskStatusToString(TaskStatus taskStatus) {
  Map<String, String> map = new LinkedHashMap<>();
  map.put("task_id", taskStatus.getTaskId().getValue());
  map.put("slave_id", taskStatus.getSlaveId().getValue());
  map.put("state", taskStatus.getState().toString());
  if (taskStatus.hasMessage()) {
    map.put("message", taskStatus.getMessage());
  }
  return JSONValue.toJSONString(map);
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:14,代碼來源:PrettyProtobuf.java

示例8: taskInfoToString

import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
 * Pretty-print mesos protobuf TaskInfo.
 * <p/>
 * XXX(erikdw): not including command, container (+data), nor health_check.
 */
public static String taskInfoToString(TaskInfo task) {
  Map<String, String> map = new LinkedHashMap<>();
  map.put("task_id", task.getTaskId().getValue());
  map.put("slave_id", task.getSlaveId().getValue());
  map.putAll(resourcesToOrderedMap(task.getResourcesList()));
  map.put("executor_id", task.getExecutor().getExecutorId().getValue());
  return JSONValue.toJSONString(map);
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:14,代碼來源:PrettyProtobuf.java

示例9: handleRequest

import org.json.simple.JSONValue; //導入方法依賴的package包/類
String handleRequest(JsonRequest request) throws Exception {
String output = "";

long starttime = 0;
long endtime = 0;
long period = 0;

starttime = request.getNumber("start", 0);
endtime = request.getNumber("end", 0);
period = request.getNumber("period", 0);

if (starttime == 0) { starttime = source.getStartTime(); }
if (endtime == 0) { 
    if (period > 0) {
	endtime = starttime + period;
    } else {
	endtime = source.getEndTime(); 
    }
}

LogIterator iter = source.iterator(starttime, endtime);
JSONObject data = new JSONObject();
data.put("startTime", starttime);
data.put("endTime", endtime);
long size = 0;

size = iter.size();

data.put("numEntries",  size);
if (LOG.isDebugEnabled()) {
    LOG.debug("handle(start= " + starttime + ", end=" + endtime + ", numEntries=" + size +")");
}
return JSONValue.toJSONString(data);
   }
 
開發者ID:gerritjvv,項目名稱:bigstreams,代碼行數:35,代碼來源:NumEvents.java

示例10: serialize

import org.json.simple.JSONValue; //導入方法依賴的package包/類
String serialize() {
    Map<String, Object> result = new HashMap<>();
    result.put("channel", channel);
    result.put("from", from);
    result.put("to", to);
    result.put("payload", payload);
    return JSONValue.toJSONString(result);
}
 
開發者ID:StarTux,項目名稱:Connect,代碼行數:9,代碼來源:Message.java

示例11: encode

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public String encode(Object object) throws Exception {
    return JSONValue.toJSONString(object);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:4,代碼來源:SimpleJsonCodec.java

示例12: toString

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public String toString() {
return JSONValue.toJSONString(root);
   }
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:4,代碼來源:JsonGenerator.java

示例13: monitor

import org.json.simple.JSONValue; //導入方法依賴的package包/類
@RequestMapping(value = "/all", method = RequestMethod.GET)
@ResponseBody
public String monitor(HttpServletRequest request, String familia) {
	return JSONValue.toJSONString(ejecutar(request));
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:6,代碼來源:MonitorSystemController.java

示例14: execute

import org.json.simple.JSONValue; //導入方法依賴的package包/類
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Tuple input, BasicOutputCollector collector) {   //Tuple;ranking
	// TODO Auto-generated method stub
	List<List> merging = (List) JSONValue.parse(input.getString(0));
	for(List pair : merging) {
		Integer existingIndex = find(pair.get(0));
		if(null != existingIndex) {
			_rankings.set(existingIndex, pair);
		} else {
			_rankings.add(pair);
		}
		Collections.sort(_rankings, new Comparator<List>() {
			@Override
			public int compare(List o1, List o2) {
				// TODO Auto-generated method stub
				return compare1(o1, o2);
			}
		});

		if(_rankings.size() > _count) {
			_rankings.subList(_count, _rankings.size()).clear();
		}
	}

	long currentTime = System.currentTimeMillis();
	if(_lastTime == null || currentTime >= _lastTime + 2000) {
		String fullRankings = JSONValue.toJSONString(_rankings);
		collector.emit(new Values(fullRankings));
		LOG.info("Rankings:\t"+fullRankings);
		System.out.println("Rankings:\t"+fullRankings);
		_lastTime = currentTime;
		//jedis.lpush("result", fullRankings);
	}

	/**
	 * 保持固定長度,避免內存占用過多溢�?
	 */
	/*
	long len = jedis.llen("result");
	if(len > 100) {
		jedis.rpop("result");
	}*/
}
 
開發者ID:MBtech,項目名稱:stormbenchmark,代碼行數:45,代碼來源:MergeObjectsBolt.java

示例15: createJsonMessage

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public static String createJsonMessage(Map<String, Object> jsonMap) {
	return JSONValue.toJSONString(jsonMap);
}
 
開發者ID:carlosCharz,項目名稱:fcmxmppserverv2,代碼行數:4,代碼來源:MessageHelper.java


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