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


Java JSONValue類代碼示例

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


JSONValue類屬於org.json.simple包,在下文中一共展示了JSONValue類的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: execute

import org.json.simple.JSONValue; //導入依賴的package包/類
@Override
public Object execute(String script) {
    StringBuilder sb = new StringBuilder();
    // Callback for scripts that want to send some message back to page-inspection.
    // We utilize custom alert handling of WebEngine for this purpose.
    sb.append("postMessageToNetBeans=function(e) {alert('"); // NOI18N
    sb.append(WebBrowserImpl.PAGE_INSPECTION_PREFIX);
    sb.append("'+JSON.stringify(e));};\n"); // NOI18N
    String quoted = '\"'+JSONValue.escape(script)+'\"';
    // We don't want to depend on what is the type of WebBrowser.executeJavaScript()
    // for various types of script results => we stringify the result
    // (i.e. pass strings only through executeJavaScript()). We decode
    // the strigified result then.
    sb.append("JSON.stringify({result : eval(").append(quoted).append(")});"); // NOI18N
    String wrappedScript = sb.toString();
    Object result = browserTab.executeJavaScript(wrappedScript);
    String txtResult = result.toString();
    try {
        JSONObject jsonResult = (JSONObject)JSONValue.parseWithException(txtResult);
        return jsonResult.get("result"); // NOI18N
    } catch (ParseException ex) {
        Logger.getLogger(ScriptExecutorImpl.class.getName()).log(Level.INFO, null, ex);
        return ScriptExecutor.ERROR_RESULT;
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:26,代碼來源:ScriptExecutorImpl.java

示例3: 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

示例4: 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

示例5: setRulebaseHtmlFile

import org.json.simple.JSONValue; //導入依賴的package包/類
/**
 * This function writes the info of the rulbase to the html file
 * @param htmlFile The html to write to
 * @param details {@link FileDetails} contain info about the html file
 * @throws IOException
 */
public void setRulebaseHtmlFile(PrintStream htmlFile , FileDetails details) throws IOException{

    htmlFile.println("\t\tvar rulebase = " + details.getRulebaseData().getRulebaseDataContent() + ";");
    htmlFile.print("\t\tvar uid_to_name = ");
    htmlFile.print(JSONValue.toJSONString(details.getUidToName()));
    htmlFile.println(";");

    htmlFile.print("\t\tvar failed_creating_layer = ");
    htmlFile.print(JSONValue.toJSONString(details.getRulebaseData().isFailedCreatingRulebase()));
    htmlFile.println(";");

    htmlFile.print("\t\tvar inline_layer_uid_to_file_name = ");
    htmlFile.print(JSONValue.toJSONString(details.getRulebaseData().getInlineLayerUidToFileNameMap()));
    htmlFile.println(";");

    setDataInHtmlFile(htmlFile, details);
}
 
開發者ID:CheckPoint-APIs-Team,項目名稱:ShowPolicyPackage,代碼行數:24,代碼來源:HtmlUtils.java

示例6: checkForUpdates

import org.json.simple.JSONValue; //導入依賴的package包/類
/**
 * Checks if updates are available.
 */
private void checkForUpdates() {
	try {
		URL url = new URL("https://api.spiget.org/v2/resources/50955/versions?size=1&sort=-id");
		
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.addRequestProperty("User-Agent", "EmojiChat Update Checker"); // Sets the user-agent
		
		InputStream inputStream = connection.getInputStream();
		InputStreamReader reader = new InputStreamReader(inputStream);
		
		JSONArray value = (JSONArray) JSONValue.parseWithException(reader);
		
		latestVersion = Double.parseDouble(((JSONObject) value.get(value.size() - 1)).get("name").toString());
		
		updateAvailable = currentVersion < latestVersion;
	} catch (Exception ignored) { // Something happened, not sure what (possibly no internet connection), so no updates available
		updateAvailable = false;
	}
}
 
開發者ID:RadBuilder,項目名稱:EmojiChat,代碼行數:23,代碼來源:EmojiChatUpdateChecker.java

示例7: createHar

import org.json.simple.JSONValue; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
private void createHar(String pt, String rt) {
    Har<String, Log> har = new Har<>();
    Page p = new Page(pt, har.pages());
    har.addPage(p);
    for (Object res : (JSONArray) JSONValue.parse(rt)) {
        JSONObject jse = (JSONObject) res;
        if (jse.size() > 14) {
            Entry e = new Entry(jse.toJSONString(), p);
            har.addEntry(e);
        }
    }
    har.addRaw(pt, rt);
    Control.ReportManager.addHar(har, (TestCaseReport) Report,
            escapeName(Data));
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:17,代碼來源:Performance.java

示例8: getPageMap

import org.json.simple.JSONValue; //導入依賴的package包/類
/**
    * parse and map the pages and its page timings
    *
    * @param data json data
    * @return json map
    */
  
private static JSONObject getPageMap(String data) {
       JSONObject pageMap = new JSONObject();
       JSONObject ob = (JSONObject) JSONValue.parse(data);
       for (Object tc : ob.keySet()) {
           JSONArray hars = (JSONArray) ((JSONObject) ob.get(tc)).get("har");
           for (Object e : hars) {
               JSONObject har = (JSONObject) ((JSONObject) e).get("har");
               JSONObject page = (JSONObject) ((JSONArray) (((JSONObject) har.get("log")).get("pages"))).get(0);
               Object pagename = ((JSONObject) har.get("config")).get("name");
               if (!pageMap.containsKey(pagename)) {
                   pageMap.put(pagename, new JSONArray());
               }
               JSONObject pageData = (JSONObject) page.get("pageTimings");
               pageData.put("config", har.get("config"));
               ((JSONArray) pageMap.get(pagename)).add(pageData);
           }
       }
       return pageMap;
   }
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:27,代碼來源:Performance.java

示例9: executeImpl

import org.json.simple.JSONValue; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public JSONArray executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
        ParseException
{
    JSONArray jsonUsers = (JSONArray) JSONValue.parseWithException(req.getContent().getContent());

    JSONArray result = new JSONArray();

    for (Object o : jsonUsers)
    {
        String user = (o == null ? null : o.toString());
        if (user != null)
        {
            JSONObject item = new JSONObject();
            item.put(user, subscriptionService.follows(userId, user));
            result.add(item);
        }
    }

    return result;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:22,代碼來源:SubscriptionServiceFollowsPost.java

示例10: executeImpl

import org.json.simple.JSONValue; //導入依賴的package包/類
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
        ParseException
{
    JSONArray jsonUsers = (JSONArray) JSONValue.parseWithException(req.getContent().getContent());

    for (Object o : jsonUsers)
    {
        String user = (o == null ? null : o.toString());
        if (user != null)
        {
            subscriptionService.follow(userId, user);
        }
    }

    return null;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:17,代碼來源:SubscriptionServiceFollowPost.java

示例11: executeImpl

import org.json.simple.JSONValue; //導入依賴的package包/類
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
        ParseException
{
    JSONObject obj = (JSONObject) JSONValue.parseWithException(req.getContent().getContent());

    Object setPrivate = obj.get("private");

    if (setPrivate != null)
    {
        if (setPrivate.toString().equalsIgnoreCase("true"))
        {
            subscriptionService.setSubscriptionListPrivate(userId, true);
        } else if (setPrivate.toString().equalsIgnoreCase("false"))
        {
            subscriptionService.setSubscriptionListPrivate(userId, false);
        }
    }

    return super.executeImpl(userId, req, res);
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:21,代碼來源:SubscriptionServicePrivateListPut.java

示例12: executeImpl

import org.json.simple.JSONValue; //導入依賴的package包/類
public JSONObject executeImpl(String userId, WebScriptRequest req, WebScriptResponse res) throws IOException,
        ParseException
{
    JSONArray jsonUsers = (JSONArray) JSONValue.parseWithException(req.getContent().getContent());

    for (Object o : jsonUsers)
    {
        String user = (o == null ? null : o.toString());
        if (user != null)
        {
            subscriptionService.unfollow(userId, user);
        }
    }

    return null;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:17,代碼來源:SubscriptionServiceUnfollowPost.java

示例13: decodeJSON

import org.json.simple.JSONValue; //導入依賴的package包/類
/**
 * decodes JSON formatted text into a map.
 *
 * @return Map parsed from a JSON formatted string
 * <p>
 *  If the json text is not a map, a map with the key "value" will be returned.
 *  the value of "value" will either be an List, String, Number, Boolean, or null
 *  <p>
 *  if the String is formatted badly, null is returned
 */
public static Map decodeJSON(String json) {
	try {
		Object object = JSONValue.parse(json);
		if (object instanceof Map) {
			return (Map) object;
		}
		// could be : ArrayList, String, Number, Boolean
		Map map = new HashMap();
		map.put("value", object);
		return map;
	} catch (Throwable t) {
		Debug.out("Warning: Bad JSON String: " + json, t);
		return null;
	}
}
 
開發者ID:BiglySoftware,項目名稱:BiglyBT,代碼行數:26,代碼來源:JSONUtils.java

示例14: MongoHandler

import org.json.simple.JSONValue; //導入依賴的package包/類
public MongoHandler(Socket client, Request req, MongoClient mongoconn) throws Exception {
    Object obj = JSONValue.parse(req.getContent());
    JSONObject jobj = (JSONObject)obj;
    System.out.println(req.getContent());
    if((database = (String)jobj.get("database")) == null) {
        throw new Exception("Database not specified");
    }
    if((collection = (String)jobj.get("collection")) == null){
        throw new Exception("Collection not specified");
    }
    if((operation = (String)jobj.get("operation")) == null){
        throw new Exception("Operation not specified");
    }
    data = (JSONObject)jobj.get("data");
    this.dbconn = mongoconn;

    mdb = dbconn.getDatabase(database);
    mcollection = mdb.getCollection(collection);
    this.client = client;
}
 
開發者ID:aninditamondal,項目名稱:FireAnt,代碼行數:21,代碼來源:MongoHandler.java

示例15: readCommandLineOpts

import org.json.simple.JSONValue; //導入依賴的package包/類
public static Map readCommandLineOpts() {
	Map ret = new HashMap();
	String commandOptions = System.getProperty("leaf.options");
	if (commandOptions != null) {
		String[] configs = commandOptions.split(",");
		for (String config : configs) {
			config = URLDecoder.decode(config);
			String[] options = config.split("=", 2);
			if (options.length == 2) {
				Object val = JSONValue.parse(options[1]);
				if (val == null) {
					val = options[1];
				}
				ret.put(options[0], val);
			}
		}
	}
	return ret;
}
 
開發者ID:weizhenyi,項目名稱:leaf-snowflake,代碼行數:20,代碼來源:Utils.java


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