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