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