net.sf.json.JSON类的使用及代码示例

x33g5p2x  于2022-01-22 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(235)

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

JSON介绍

暂无

代码示例

代码示例来源:origin: geoserver/geoserver

/** Utility method to print out the contents of a json object. */
protected void print(JSON json) {
  System.out.println(json.toString(2));
}

代码示例来源:origin: org.geoserver/rest

@Override
protected void write(Object object, OutputStream out) throws IOException {
  //TODO: character set
  Writer outWriter = new BufferedWriter(new OutputStreamWriter(out));
  //JD: why does this initial flush occur?
  outWriter.flush();
  JSON obj = (JSON)toJSONObject(object);
  obj.write(outWriter);
  outWriter.flush();
}

代码示例来源:origin: org.jenkins-ci.plugins/pipeline-utility-steps

@Override
protected Void run() throws Exception {
  if (step.getJson() == null) {
    throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingJSON(step.getDescriptor().getFunctionName()));
  }
  if (StringUtils.isBlank(step.getFile())) {
    throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingFile(step.getDescriptor().getFunctionName()));
  }
  if (isNotBlank(step.getFile()) && ws == null) {
    // Need a workspace if we are writing to a file.
    throw new MissingContextVariableException(FilePath.class);
  }
  FilePath path = ws.child(step.getFile());
  if (path.isDirectory()) {
    throw new FileNotFoundException(Messages.JSONStepExecution_fileIsDirectory(path.getRemote()));
  }
  try (OutputStreamWriter writer = new OutputStreamWriter(path.write())) {
    if (step.getPretty() > 0) {
      writer.write(step.getJson().toString(step.getPretty()));
    } else {
      step.getJson().write(writer);
    }
  }
  return null;
}

代码示例来源:origin: edu.uiuc.ncsa.myproxy/oa4mp-server-loader-oauth2

public static CreateRequest createRequest(AdminClient adminClient, TypeClient typeClient, ActionCreate actionCreate,
                     OA2Client client, JSON json) {
  if (json.isArray()) {
    throw new IllegalArgumentException("Error: cannot create a client from a JSON array -- it must be an map (JSON object) of key/value pairs");
  }
  return new CreateRequest(adminClient, client, (JSONObject) json);
}

代码示例来源:origin: edu.uiuc.ncsa.myproxy/oa4mp-server-loader-oauth2

if(!temp.isEmpty()) {
  if (!temp.isArray()) {
    ldap = (JSONObject) temp;
  } else {

代码示例来源:origin: org.geoserver/gs-restconfig

@Override
public void writeInternal(Map<?, ?> map, HttpOutputMessage outputMessage)
    throws IOException, HttpMessageNotWritableException {
  // TODO: character set
  Writer outWriter = new BufferedWriter(new OutputStreamWriter(outputMessage.getBody()));
  // JD: why does this initial flush occur?
  outWriter.flush();
  JSON obj = (JSON) toJSONObject(map);
  obj.write(outWriter);
  outWriter.flush();
}

代码示例来源:origin: jenkinsci/pipeline-utility-steps-plugin

@Override
protected Void run() throws Exception {
  FilePath ws = getContext().get(FilePath.class);
  assert ws != null;
  if (step.getJson() == null) {
    throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingJSON(step.getDescriptor().getFunctionName()));
  }
  if (StringUtils.isBlank(step.getFile())) {
    throw new IllegalArgumentException(Messages.WriteJSONStepExecution_missingFile(step.getDescriptor().getFunctionName()));
  }
  FilePath path = ws.child(step.getFile());
  if (path.isDirectory()) {
    throw new FileNotFoundException(Messages.JSONStepExecution_fileIsDirectory(path.getRemote()));
  }
  try (OutputStreamWriter writer = new OutputStreamWriter(path.write(), "UTF-8")) {
    if (step.getPretty() > 0) {
      writer.write(step.getJson().toString(step.getPretty()));
    } else {
      step.getJson().write(writer);
    }
  }
  return null;
}

代码示例来源:origin: OpenNMS/opennms

protected static JSONObject wrapArray(final JSON json) {
    if (json.isArray()) {
      final JSONObject wrapper = new JSONObject();
      wrapper.put("elements", json);
      return wrapper;

    } else {
      return (JSONObject) json;
    }
  }
}

代码示例来源:origin: geoserver/geoserver

/** Utility method to print out the contents of a json object. */
protected void print(JSON json) {
  if (isQuietTests()) {
    return;
  }
  System.out.println(json.toString(2));
}

代码示例来源:origin: pl.edu.icm.yadda/yaddaweb-lite-core

protected void writeJSON(Map model, HttpServletRequest request,
    HttpServletResponse response) throws Exception {
  JSON json = createJSON(model, request, response);
  json = (JSON) (((JSONObject) json).get(modelItemKey));
  json.write(response.getWriter());
}

代码示例来源:origin: woder/TorchBot

public UUID getUUIDName(String name){
  BiMap<String, UUID>invmap= names.inverse();
  UUID u = null;
  if(invmap.containsKey(name)){
    u = invmap.get(name);
  }else{
    String result = c.sendGetRequest("https://api.mojang.com/users/profiles/minecraft/" + name);
    JSON jsonr = JSONSerializer.toJSON(result);
    if(!jsonr.isArray()){
      JSONObject js = (JSONObject) jsonr;
      u = new UUID(new BigInteger(js.getString("id").substring(0, 16), 16).longValue(),new BigInteger(js.getString("id").substring(16), 16).longValue());               
      names.put(u, name);
    }
  }
  return u;
}

代码示例来源:origin: gooddata/GoodData-CL

/**
 * Helper method: prints out a JSON object
 *
 * @param o the JSON Object
 */
public static void printJson(JSON o) {
  l.info(o.toString(2));
}

代码示例来源:origin: org.kohsuke.stapler/stapler

protected boolean handleJSON(StaplerResponse rsp, Object response) throws IOException {
    if (response instanceof JSON) {
      rsp.setContentType(Flavor.JSON.contentType);
      ((JSON)response).write(rsp.getWriter());
      return true;
    }
    return false;
  }
}

代码示例来源:origin: edu.uiuc.ncsa.myproxy/oa4mp-server-loader-oauth2

public static AttributeSetClientRequest createRequest(AdminClient aSubj,
                        TypeAttribute typeAttribute,
                        ActionSet actionSet,
                        OA2Client cTarget,
                        JSON content) {
  if (content.isArray()) {
    throw new GeneralException("Content must be a map of attributes to set");
  }
  return new AttributeSetClientRequest(aSubj, cTarget, (JSONObject) content);
}

代码示例来源:origin: undera/jmeter-plugins

private String formatJSON(String json) {
  JSON object = JSONSerializer.toJSON(json, config);
  return object.toString(4); // TODO: make a property to manage the indent
}

代码示例来源:origin: org.hudsonci.stapler/stapler-core

protected boolean handleJSON(StaplerResponse rsp, Object response) throws IOException {
    if (response instanceof JSON) {
      rsp.setContentType(Flavor.JSON.contentType);
      ((JSON)response).write(rsp.getWriter());
      return true;
    }
    return false;
  }
}

代码示例来源:origin: org.opennms.protocols/org.opennms.protocols.xml

protected static JSONObject wrapArray(final JSON json) {
    if (json.isArray()) {
      final JSONObject wrapper = new JSONObject();
      wrapper.put("elements", json);
      return wrapper;

    } else {
      return (JSONObject) json;
    }
  }
}

代码示例来源:origin: stackoverflow.com

net.sf.json.xml.XMLSerializer xmlSerializer = new net.sf.json.xml.XMLSerializer(); 
JSON json = xmlSerializer.read( xmlString );  
System.out.println( json.toString(2) );

代码示例来源:origin: stapler/stapler

protected boolean handleJSON(StaplerResponse rsp, Object response) throws IOException {
    if (response instanceof JSON) {
      rsp.setContentType(Flavor.JSON.contentType);
      ((JSON)response).write(rsp.getWriter());
      return true;
    }
    return false;
  }
}

代码示例来源:origin: com.cerner.ccl.comm/j4ccl-ssh

/**
 * Populate a fixed-length list from JSON data objects.
 *
 * @param sourceJson
 *            A {@link JSON} object representing an array of JSON data objects or a single JSON data object from
 *            which data will be pulled.
 * @param field
 *            A {@link Field} object representing the fixed-length list to be populated.
 * @param recordList
 *            A {@link RecordList} containing records into which values will be populated.
 */
private static void putFixedListFromJson(final JSON sourceJson, final Field field, final RecordList recordList) {
  if (sourceJson.isArray())
    putFixedListDeepFromJson((JSONArray) sourceJson, field, recordList);
  else
    putFixedListShallowFromJson((JSONObject) sourceJson, field, recordList);
}

相关文章