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


Java JSONValue.parse方法代碼示例

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


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

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

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

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

示例4: authFacebookLogin

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public FbLoginInfo authFacebookLogin(String accessToken) {
FbLoginInfo fbLoginInfo = null;
      try {
      	JSONObject jsonmap = (JSONObject) JSONValue.parse(
          		readURL(new URL("https://graph.facebook.com/me?access_token=" + accessToken)));
      	fbLoginInfo = new FbLoginInfo(); 
      	fbLoginInfo.id = (String)jsonmap.get("id");
      	fbLoginInfo.firstName = (String)jsonmap.get("first_name");
      	fbLoginInfo.lastName = (String)jsonmap.get("last_name");
      	fbLoginInfo.email = (String)jsonmap.get("email");
      	logger.info("Facebook login : id=" + fbLoginInfo.id + " fname=" + fbLoginInfo.firstName + " lastname=" + 
      			fbLoginInfo.lastName + " email=" + fbLoginInfo.email);
      } catch (Throwable ex) {
          logger.warn("Facebook login failed for token " + accessToken);
      }
      return fbLoginInfo;
  }
 
開發者ID:kenfrank,項目名稱:trivolous,代碼行數:18,代碼來源:Facebook.java

示例5: connect

import org.json.simple.JSONValue; //導入方法依賴的package包/類
private boolean connect() {
     try {
         final URLConnection connection = this.url.openConnection();
         connection.setConnectTimeout(5000);
         connection.addRequestProperty("User-Agent", "CS-CoreLib Loader (by mrCookieSlime)");
         connection.setDoOutput(true);

         final BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
         final JSONArray array = (JSONArray) JSONValue.parse(reader.readLine());
         download = traceURL(((String) ((JSONObject) array.get(array.size() - 1)).get("downloadUrl")).replace("https:", "http:"));
         file = new File("plugins/" + (String) ((JSONObject) array.get(array.size() - 1)).get("name") + ".jar");
         
         return true;
     } catch (IOException e) {
     	System.err.println(" ");
     	System.err.println("#################### - WARNING - ####################");
System.err.println(" ");
System.err.println("Could not connect to BukkitDev.");
System.err.println("Please download & install CS-CoreLib manually:");
System.err.println("https://dev.bukkit.org/projects/cs-corelib");
System.err.println(" ");
System.err.println("#################### - WARNING - ####################");
System.err.println(" ");
         return false;
     }
 }
 
開發者ID:TheBusyBiscuit,項目名稱:CS-CoreLib,代碼行數:27,代碼來源:CSCoreLibLoader.java

示例6: appendString

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public void appendString(String jsonObject){
	Object obj = JSONValue.parse(jsonObject);
	if (obj instanceof JSONObject){
		workingGroup.add((JSONObject)obj);
	}
	if (obj instanceof JSONArray){
		for (Object object:((JSONArray)obj)){
			if (object.toString().isEmpty()) continue;
			if (object instanceof JSONArray){
				appendString(object.toString());
			} else {
				workingGroup.add((JSONObject)JSONValue.parse(object.toString()));	
			}
		}			
	}
}
 
開發者ID:FabioZumbi12,項目名稱:UltimateChat,代碼行數:17,代碼來源:UltimateFancy.java

示例7: jsonQuery

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public Object jsonQuery(String postfix) throws IOException {
    URL url = new URL(SITE_PREFIX + spigetId + postfix);
    URLConnection conn = url.openConnection();
    conn.setRequestProperty("User-Agent", USER_AGENT);
    if(((HttpURLConnection)conn).getResponseCode() == 404)
        return null;
    return JSONValue.parse(new InputStreamReader((InputStream)conn.getContent()));
}
 
開發者ID:upperlevel,項目名稱:uppercore,代碼行數:9,代碼來源:SpigetUpdateChecker.java

示例8: main

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public static void main(String args[]) throws ParserConfigurationException, IOException, TransformerException {
	Reader reader = new FileReader(args[0]);
	Object object = JSONValue.parse(reader);
	reader.close();
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	DocumentBuilder docBuilder = dbf.newDocumentBuilder();
	Document doc = toXML(docBuilder, object);
	TransformerFactory transformerFactory = TransformerFactory.newInstance();
	Transformer transformer = transformerFactory.newTransformer();
	Source source = new DOMSource(doc);
	Result result = new StreamResult(new File(args[1]));
	transformer.transform(source, result);
}
 
開發者ID:Bibliome,項目名稱:bibliome-java-utils,代碼行數:14,代碼來源:JSONUtils.java

示例9: getCode

import org.json.simple.JSONValue; //導入方法依賴的package包/類
/**
 * 例外発生時のステータスコードを取得.
 * @return ステータスコード
 */
public final String getCode() {
    String code = "";
    String msg = this.getMessage();
    JSONObject json = (JSONObject) JSONValue.parse(msg);
    code = (String) json.get("code");
    return code;
}
 
開發者ID:personium,項目名稱:personium-core,代碼行數:12,代碼來源:PersoniumException.java

示例10: readJsonFromUrl

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public static JSONObject readJsonFromUrl(String url) {
	try {
		InputStream is = new URL(url).openStream();
		BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
		String jsonText = readAll(rd);
		JSONObject json = (JSONObject) JSONValue.parse(jsonText);
		is.close();
		return json;
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return null;
}
 
開發者ID:GigaGamma,項目名稱:SuperiorCraft,代碼行數:15,代碼來源:JsonReader.java

示例11: process

import org.json.simple.JSONValue; //導入方法依賴的package包/類
@Override
public void process(ProcessingContext<Corpus> ctx, Corpus corpus) throws ModuleException {
	try {
		AlvisAEExportResolvedObjects resObj = getResolvedObjects();
		CadixeExportContext exportContext = new CadixeExportContext(ctx);
		if (schemaFile != null) {
			Reader r = new FileReader(schemaFile);
			exportContext.schema = JSONValue.parse(r);
			if (exportContext.schema == null)
				processingException("could not parse " + schemaFile + " as JSON");
			r.close();
		}
		for (Document doc : Iterators.loop(documentIterator(exportContext.evalCtx, corpus))) {
			JSONObject json = documentToJSON(doc, exportContext);
			OutputFile outFile = new OutputFile(outDir, resObj.fileName.evaluateString(exportContext.evalCtx, doc));
			TargetStream target = new FileTargetStream("UTF-8", outFile);
			Writer w = target.getWriter();
			json.writeJSONString(w);
			w.close();
		}
	}
	catch (UnsupportedEncodingException uee) {
		rethrow(uee);
	}
	catch (FileNotFoundException fnfe) {
		rethrow(fnfe);
	}
	catch (IOException ioe) {
		rethrow(ioe);
	}
}
 
開發者ID:Bibliome,項目名稱:alvisnlp,代碼行數:32,代碼來源:AlvisAEWriter.java

示例12: parse

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public Map<String, Object> parse(String activityType, String activitySummary) throws JSONException
{
	JSONObject json = (JSONObject)JSONValue.parse(activitySummary);
	Map<String, Object> map = convertJSONObjectToMap(json);
	processActivitySummary(activityType, map);
	return map;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:8,代碼來源:ActivitySummaryParser.java

示例13: init

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public void init() {
    try {
        String rawData = FileScanner.readFile(new File(getFile()));
        this.data = (JSONObject) JSONValue.parse(rawData);
    } catch (Exception ex) {
        LOG.error(ex.getMessage(), ex);
    }
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:9,代碼來源:ReportingModuleSettings.java

示例14: getRefData

import org.json.simple.JSONValue; //導入方法依賴的package包/類
public static JSONObject getRefData(JSONObject req) {
    try {
        String data = Tools.readFile(new File(DashBoardData.refHars(), req.get("name").toString() + ".har.ref"));
        return (JSONObject) JSONValue.parse(data);
    } catch (Exception ex) {
        LOG.log(Level.WARNING, "Error while reading har ref file", ex);
    }
    return null;
}
 
開發者ID:CognizantQAHub,項目名稱:Cognizant-Intelligent-Test-Scripter,代碼行數:10,代碼來源:HarCompareHandler.java

示例15: parseActivitySummary

import org.json.simple.JSONValue; //導入方法依賴的package包/類
private Map<String, Object> parseActivitySummary(ActivityFeedEntity entity)
{
	String activityType = entity.getActivityType();
	String activitySummary = entity.getActivitySummary();
	JSONObject json = (JSONObject)JSONValue.parse(activitySummary);
	return Activity.getActivitySummary(json, activityType);
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:8,代碼來源:RepoService.java


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