net.minidev.json.JSONObject.writeJSONString()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中net.minidev.json.JSONObject.writeJSONString()方法的一些代码示例,展示了JSONObject.writeJSONString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.writeJSONString()方法的具体详情如下:
包路径:net.minidev.json.JSONObject
类名称:JSONObject
方法名:writeJSONString

JSONObject.writeJSONString介绍

[英]serialize Object as json to an stream
[中]将对象序列化为json到流

代码示例

代码示例来源:origin: org.btrplace/scheduler-json

/**
 * Write an instance
 *
 * @param instance the instance to write
 * @param a        the stream to write on.
 * @throws IllegalArgumentException if an error occurred while writing the json
 */
public static void write(Instance instance, Appendable a) {
  try {
    InstanceConverter c = new InstanceConverter();
    c.toJSON(instance).writeJSONString(a);
  } catch (IOException | JSONConverterException e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: org.btrplace/scheduler-json

/**
 * Write a reconfiguration plan.
 *
 * @param plan the plan to write
 * @param a    the stream to write on.
 * @throws IllegalArgumentException if an error occurred while writing the json
 */
public static void write(ReconfigurationPlan plan, Appendable a) {
  try {
    ReconfigurationPlanConverter c = new ReconfigurationPlanConverter();
    c.toJSON(plan).writeJSONString(a);
  } catch (IOException | JSONConverterException e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: btrplace/scheduler

/**
 * Write a reconfiguration plan.
 *
 * @param plan the plan to write
 * @param a    the stream to write on.
 * @throws IllegalArgumentException if an error occurred while writing the json
 */
public static void write(ReconfigurationPlan plan, Appendable a) {
  try {
    ReconfigurationPlanConverter c = new ReconfigurationPlanConverter();
    c.toJSON(plan).writeJSONString(a);
  } catch (IOException | JSONConverterException e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: 01org/graphbuilder

@Override
public StringWriter edataWriter(Graph g) {
 JSONObject obj = new JSONObject();
 obj.put("edataList", ((GLGraph) g).edatalist());
 StringWriter out = new StringWriter();
 try {
  obj.writeJSONString(out);
 } catch (IOException e) {
  e.printStackTrace();
 }
 return out;
}

代码示例来源:origin: btrplace/scheduler

/**
 * Write an instance
 *
 * @param instance the instance to write
 * @param a        the stream to write on.
 * @throws IllegalArgumentException if an error occurred while writing the json
 */
public static void write(Instance instance, Appendable a) {
  try {
    InstanceConverter c = new InstanceConverter();
    c.toJSON(instance).writeJSONString(a);
  } catch (IOException | JSONConverterException e) {
    throw new IllegalArgumentException(e);
  }
}

代码示例来源:origin: 01org/graphbuilder

/**
 * @param g
 * @return A JSON string of the vid2lvid map of a GLGraph.
 */
public StringWriter vid2lvidWriter(GLGraph g) {
 JSONObject obj = new JSONObject();
 obj.put("vid2lvid", g.vid2lvid());
 StringWriter out = new StringWriter();
 try {
  obj.writeJSONString(out);
 } catch (IOException e) {
  e.printStackTrace();
 }
 return out;
}

代码示例来源:origin: tomsik68/mclauncher-api

public void saveTo(File file) throws Exception {
  JSONObject obj = new JSONObject();
  if (file.exists()) {
    MCLauncherAPI.log.fine("The file already exists. YDLoginService won't overwrite client token.");
    FileReader fileReader = new FileReader(file);
    obj = (JSONObject) JSONValue.parse(fileReader);
    fileReader.close();
    if (obj.containsKey("clientToken"))
      return;
    file.delete();
  }
  FileUtils.createFileSafely(file);
  MCLauncherAPI.log.fine("Writing client token...");
  // file.createNewFile();
  obj.put("clientToken", clientToken.toString());
  FileWriter fw = new FileWriter(file);
  obj.writeJSONString(fw, JSONStyle.NO_COMPRESS);
  fw.flush();
  fw.close();
}

代码示例来源:origin: 01org/graphbuilder

@Override
public StringWriter structWriter(Graph g) {
 JSONObject obj = new JSONObject();
 StringWriter out = new StringWriter();
 int count = 0;
 List sortedKey = ((SimpleGraph) g).vertices();
 Collections.sort(sortedKey);
 try {
  for (int i = 0; i < sortedKey.size(); i++) {
   obj.clear();
   obj.put("source", sortedKey.get(i));
   obj.put("targets", ((SimpleGraph) g).outEdgeTargetIds(sortedKey.get(i)));
   obj.writeJSONString(out);
   out.append("\n");
  }
 } catch (IOException e) {
  e.printStackTrace();
 }
 return out;
}

代码示例来源:origin: tomsik68/mclauncher-api

@Override
public void write(IProfile[] profiles) throws Exception {
  JSONObject jRoot, authDb;
  if (!dest.exists()) {
    FileUtils.createFileSafely(dest);
    jRoot = new JSONObject();
    authDb = new JSONObject();
  } else {
    MCLauncherAPI.log.fine("Existing profile storage file found. Loading profiles in case they would be overwritten.");
    FileReader fileReader = new FileReader(dest);
    jRoot = (JSONObject) JSONValue.parse(fileReader);
    fileReader.close();
    authDb = (JSONObject) jRoot.get("authenticationDatabase");
    if(authDb == null){
      authDb = new JSONObject();
    }
  }
  for (IProfile p : profiles) {
    if (!(p instanceof YDAuthProfile))
      throw new IllegalArgumentException("You can only save YDAuthProfile with this system!");
    YDAuthProfile profile = (YDAuthProfile)p;
    authDb.put(profile.getUUID().replace("-", ""), profile.toJSON());
  }
  jRoot.put("authenticationDatabase", authDb);
  FileWriter fw = new FileWriter(dest);
  jRoot.writeJSONString(fw, JSONStyle.NO_COMPRESS);
  fw.flush();
  fw.close();
}

代码示例来源:origin: arago/rike

JSONObject ret = new JSONObject();
  ret.put("error", ex.getMessage());
  ret.writeJSONString(response.getWriter());
} catch (Throwable t) {
  logger.log(Level.SEVERE, "action " + actionName + " failed ", t);

代码示例来源:origin: 01org/graphbuilder

@Override
 public StringWriter vrecordWriter(VertexRecord vrec) {
  JSONObject obj = new JSONObject();
  obj.put("gvid", vrec.vid());
  obj.put("owner", vrec.owner());
  obj.put("inEdges", vrec.inEdges());
  obj.put("outEdges", vrec.outEdges());
  obj.put("mirrors", vrec.mirrorList());
  obj.put("vdata", vrec.vdata());
  StringWriter out = new StringWriter();
  try {
   obj.writeJSONString(out);
  } catch (IOException e) {
   e.printStackTrace();
  }
  return out;
 }
}

代码示例来源:origin: 01org/graphbuilder

@Override
 public StringWriter structWriter(Graph graph) {
  JSONObject obj = new JSONObject();
  GLGraph g = (GLGraph) graph;
  obj.put("numVertices", g.numVertices());
  obj.put("numEdges", g.numEdges());
  obj.put("csr", g.csr().toJSONObj());
  obj.put("csc", g.csc().toJSONObj());
  obj.put("c2rMap", g.c2rMap());
  StringWriter out = new StringWriter();
  try {
   obj.writeJSONString(out);
  } catch (IOException e) {
   e.printStackTrace();
  }
  return out;
 }
}

相关文章