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


Java JSONObject.write方法代碼示例

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


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

示例1: doPost

import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    req.setCharacterEncoding("UTF-8");
    resp.setCharacterEncoding("UTF-8");
    JSONObject object = new JSONObject();
    JSONArray array = new JSONArray();
    List<Language> allLanguage = LanguagePool.getAllLanguage();
    for (Language thisLanguage : allLanguage) {
        JSONObject child = new JSONObject();
        child.put("id", thisLanguage.getId());
        child.put("name", thisLanguage.getName());
        array.put(child);
    }
    object.put("lang", array);
    resp.setContentType("application/json");
    object.write(resp.getWriter());
}
 
開發者ID:ProgramLeague,項目名稱:Avalon-Executive,代碼行數:18,代碼來源:GetAllLang.java

示例2: matchesIdToNames

import org.json.JSONObject; //導入方法依賴的package包/類
private static void matchesIdToNames(String[] args) {
    boolean gym = Boolean.getBoolean(args[1]);
    List<String> contests = CodeForcesSDK.getContestNames(gym);
    List<JSONObject> list = new ArrayList<>(contests.size());
    for (int contestId = contests.size() - 1; contestId > 0; contestId--) {
        JSONObject json = new JSONObject();
        json.put("contestId", contestId);
        json.put("name", contests.get(contestId));
        list.add(json);
    }

    JSONObject contestNames = new JSONObject();
    contestNames.put("status", "OK");
    contestNames.put("result", new JSONArray(list));

    String fileName = "contests/contestNames.json";
    try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName))) {
        contestNames.write(writer);
        writer.write("\n");
    } catch (Exception ex) {
        System.err.println("Couldn't write contestNames\n"
                + ex.getMessage());
    }
}
 
開發者ID:WslF,項目名稱:CF-rating-prediction,代碼行數:25,代碼來源:AdditionalExecutor.java

示例3: writeToFiles

import org.json.JSONObject; //導入方法依賴的package包/類
private static boolean writeToFiles(String filePrefix, TreeMap<String, Integer> rating, String contestId) {
    boolean result = true;
    String fileName = getFileName(contestId, filePrefix);
    JSONObject json = toJSON(rating);

    try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(fileName))) {
        json.write(writer, 2, 0);
        writer.write("\n");
    } catch (Exception ex) {
        System.err.println("Couldn't write past rating to the file\n"
                + ex.getMessage());
        result = false;
    }

    return result;
}
 
開發者ID:WslF,項目名稱:CF-rating-prediction,代碼行數:17,代碼來源:PastRatingDownloader.java

示例4: sendJsonResponse

import org.json.JSONObject; //導入方法依賴的package包/類
protected void sendJsonResponse(HttpServletResponse response, int statusCode, JSONObject jsonObj)
    throws IOException, JSONException {
  response.setStatus(statusCode);
  response.setContentType(JSON_UTF8);
  //jsonObj.writeJSONString(response.getWriter()); // used earlier with json.simple
  jsonObj.write(response.getWriter());
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:8,代碼來源:JsonRestServlet.java

示例5: sendJsonListResponse

import org.json.JSONObject; //導入方法依賴的package包/類
protected void sendJsonListResponse(HttpServletResponse response, int statusCode,
                                    List<JSONObject> jsonObjList)
    throws IOException, JSONException {
  response.setStatus(statusCode);
  response.setContentType(JSON_UTF8);
  Iterator<JSONObject> it = jsonObjList.iterator();
  while (it.hasNext()) {
    JSONObject jsonObj = it.next();
    //jsonObj.writeJSONString(response.getWriter()); // used earlier with json.simple
    jsonObj.write(response.getWriter());
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:13,代碼來源:JsonRestServlet.java

示例6: writeDataJSON

import org.json.JSONObject; //導入方法依賴的package包/類
public String writeDataJSON(Map<String, String> data, String defaultPayload) {
	String payload = defaultPayload;
	JSONObject json = new JSONObject();
	try {
		for (String key : data.keySet()) {
			json.put(key, data.get(key));
		}
		StringWriter wr = new StringWriter();
		json.write(wr);
		payload = wr.toString();
	} catch (JSONException e) {
		System.err.println("Exception (ignored): " + e);
	}
	return payload;
}
 
開發者ID:sergueik,項目名稱:SWET,代碼行數:16,代碼來源:Utils.java

示例7: write

import org.json.JSONObject; //導入方法依賴的package包/類
private void write(String startTime, String simId, String name, JSONObject json) {
    String prefix = startTime + "-" + simId;
    File file = Paths.get(this.replayPath, prefix, name + ".json").toFile();
    File dir = file.getParentFile();
    if (!dir.exists()) dir.mkdirs();

    try {
        FileWriter writer = new FileWriter(file);
        json.write(writer);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:agentcontest,項目名稱:massim,代碼行數:15,代碼來源:ReplayWriter.java

示例8: writeJSON

import org.json.JSONObject; //導入方法依賴的package包/類
private String writeJSON(JSONObject obj) {
  // e.g. 'output/wetlands1.json'
  String outFile = outputFileBase + current.incrementAndGet() + ".json";
  log.info(outFile);
  try ( BufferedWriter br = new BufferedWriter( new FileWriter( new File( outFile ) ) ) ) {
    obj.write(br);
  } catch ( IOException e ) {
    log.error("Couldn't write '" + outFile + "'", e);
    failJob( "Failed to write a response.. our fault, try again?" );
  }
  return outFile;
}
 
開發者ID:mchaynes,項目名稱:northpine,代碼行數:13,代碼來源:ScrapeJob.java


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