net.sf.json.JSON.toString()方法的使用及代码示例

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

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

JSON.toString介绍

暂无

代码示例

代码示例来源: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: 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: 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: 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: gooddata/GoodData-CL

/**
 * Writes a JSON object to a file.
 *
 * @param content  the content
 * @param fileName the file
 * @throws IOException
 */
public static void writeJSONToFile(JSON content, String fileName) throws IOException {
  BufferedWriter fw = createBufferedUtf8Writer(fileName);
  String str = content.toString(2);
  str = str.replace("�", " "); // ugly but works
  fw.write(str);
  fw.flush();
  fw.close();
}

代码示例来源: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: stackoverflow.com

import java.io.InputStream;
 import net.sf.json.JSON;
 import net.sf.json.xml.XMLSerializer;
 import org.apache.commons.io.IOUtils;
 public class ConvertXMLtoJSON {
     public static void main(String[] args) throws Exception {
         InputStream is = 
             ConvertXMLtoJSON.class.getResourceAsStream("sample-xml.xml");
         String xml = IOUtils.toString(is);
         XMLSerializer xmlSerializer = new XMLSerializer(); 
         JSON json = xmlSerializer.read( xml );  
         System.out.println( json.toString(2) );
     }
 }

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

/**
 * Create Patch Request
 */
public HttpPatch createPatch(String url, JSON data) {
  HttpPatch patch = new HttpPatch(url);
  patch.setHeader("Content-Type", "application/json");
  String string = data.toString(1);
  try {
    patch.setEntity(new StringEntity(string, "UTF-8"));
  } catch (UnsupportedEncodingException e) {
    throw new RuntimeException(e.getMessage(), e);
  }
  return patch;
}

代码示例来源: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: 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: itesla/ipst

try (FileWriter jsonFileWriter = new FileWriter(jsonFile.toFile())) {
  jsonFileWriter.write(JSONSerializer.toJSON(jsonData).toString(3));

代码示例来源:origin: jenkinsci/tfs-plugin

jsonObject = JSONObject.fromObject(requestBody);
stringRequestBody = jsonObject.toString(0);

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

} else {
  sayi("current value for " + componentName + ":");
  say(oldJSON.toString(2));

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

say(jsonObject.toString(3));
} else {
  say("No JSON object resulted from parsing.");

相关文章

微信公众号

最新文章

更多