本文整理了Java中com.github.openjson.JSONObject.toString()
方法的一些代码示例,展示了JSONObject.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.toString()
方法的具体详情如下:
包路径:com.github.openjson.JSONObject
类名称:JSONObject
方法名:toString
[英]Encodes this object as a compact JSON string, such as:
{"query":"Pizza","locations":[94043,90210]}
Note 1: this method will not output any fields with 'null' value. Override JSONStringer#entry method to have nulls printed. Note 2: this method will suppress any internal exceptions. Use JSONObject#toString(JSONStringer) method directly to handle exceptions manually.
[中]将此对象编码为压缩JSON字符串,例如:
{"query":"Pizza","locations":[94043,90210]}
注意1:此方法不会输出任何具有“null”值的字段。重写JSONStringer#entry方法以打印空值。注2:此方法将抑制任何内部异常。直接使用JSONObject#toString(JSONString)方法手动处理异常。
代码示例来源:origin: apache/tika
public static void main(String[] args) throws IOException, JSONException {
if (args.length != 1) {
System.err.println("Error: Invalid Args");
System.err.println("This tool finds names inside text");
System.err.println("Usage: <path/to/text/file>");
return;
}
try (FileInputStream stream = new FileInputStream(args[0])) {
String text = IOUtils.toString(stream);
CoreNLPNERecogniser ner = new CoreNLPNERecogniser();
Map<String, Set<String>> names = ner.recognise(text);
JSONObject jNames = new JSONObject(names);
System.out.println(jNames.toString(2));
}
}
}
代码示例来源:origin: com.googlecode.wicket-jquery-ui/wicket-kendo-ui
@Override
public String toString()
{
return this.toJSONObject().toString();
}
代码示例来源:origin: sebfz1/wicket-jquery-ui
@Override
public String toString()
{
return this.toJSONObject().toString();
}
代码示例来源:origin: com.googlecode.wicket-jquery-ui/wicket-jquery-ui-core
/**
* Converts a {@link Object} to its JSON string representation
*
* @param object the {@code Object} to convert
* @return a new JSON String
*/
public static String toString(Object object)
{
return new JSONObject(object).toString();
}
}
代码示例来源:origin: sebfz1/wicket-jquery-ui
/**
* Converts a {@link Object} to its JSON string representation
*
* @param object the {@code Object} to convert
* @return a new JSON String
*/
public static String toString(Object object)
{
return new JSONObject(object).toString();
}
}
代码示例来源:origin: org.apache.openmeetings/openmeetings-util
public static JSONObject getRoomSettings() {
return new JSONObject(roomSettings.toString());
}
代码示例来源:origin: org.wicketstuff/wicket-gchart
/**
* Generate declaration js for datatable variable.
*
* @param varname Name of datatable variable identifier.
* @return Declaration js
*/
public String toJavaScript(String varname) {
if (varname == null || varname.isEmpty()) {
throw new IllegalArgumentException("Name must not be null or empty for Javascript generation of chart datatable.");
}
StringBuilder sb = new StringBuilder();
sb.append("var ").append(varname).append(" = new google.visualization.DataTable(");
sb.append(toJSON().toString());
sb.append(");").append("\n");
return sb.toString();
}
代码示例来源:origin: com.github.openjson/openjson
/**
* Encodes this object as a compact JSON string, such as:
* <pre>{"query":"Pizza","locations":[94043,90210]}</pre>
*
* Note 1: this method will not output any fields with 'null' value.
* Override {@link JSONStringer#entry} method to have nulls printed.
*
* Note 2: this method will suppress any internal exceptions.
* Use {@link JSONObject#toString(JSONStringer)} method directly to handle exceptions manually.
*/
@Override
public String toString() {
try {
return toString(new JSONStringer());
} catch (JSONException e) {
return null;
}
}
代码示例来源:origin: com.github.openjson/openjson
/**
* Encodes this object as a human readable JSON string for debugging, such
* as:
* <pre>
* {
* "query": "Pizza",
* "locations": [
* 94043,
* 90210
* ]
* }</pre>
*
* @param indentSpaces the number of spaces to indent for each level of
* nesting.
* @return The string containing the pretty form of this.
* @throws JSONException On internal errors. Shouldn't happen.
*/
public String toString(int indentSpaces) throws JSONException {
return toString(new JSONStringer(indentSpaces));
}
代码示例来源:origin: org.apache.tika/tika-parsers
public static void main(String[] args) throws IOException, JSONException {
if (args.length != 1) {
System.err.println("Error: Invalid Args");
System.err.println("This tool finds names inside text");
System.err.println("Usage: <path/to/text/file>");
return;
}
try (FileInputStream stream = new FileInputStream(args[0])) {
String text = IOUtils.toString(stream);
CoreNLPNERecogniser ner = new CoreNLPNERecogniser();
Map<String, Set<String>> names = ner.recognise(text);
JSONObject jNames = new JSONObject(names);
System.out.println(jNames.toString(2));
}
}
}
代码示例来源:origin: com.googlecode.wicket-jquery-ui/wicket-kendo-ui
/**
* Return the JSON representation of this object<br>
* This needs to be done manually because of the xField and yField that are not properly converted (camel case issue)
*
* @return the JSON string
*/
@Override
public String toJSONString()
{
JSONObject object = new JSONObject(this);
object.put("xField", this.xField);
object.put("yField", this.yField);
return object.toString();
}
代码示例来源:origin: com.googlecode.wicket-jquery-ui/wicket-kendo-ui
/**
* Gets the JSON representation of this {@link Resource}
*/
@Override
public String toString()
{
JSONObject object = new JSONObject();
object.put("value", this.id);
object.put("text", this.text);
object.putOpt("color", this.color); // may be null
for (Entry<String, Object> entry : this.fields.entrySet())
{
object.put(entry.getKey(), entry.getValue());
}
return object.toString();
}
}
代码示例来源:origin: sebfz1/wicket-jquery-ui
/**
* Gets the JSON representation of this {@link Resource}
*/
@Override
public String toString()
{
JSONObject object = new JSONObject();
object.put("value", this.id);
object.put("text", this.text);
object.putOpt("color", this.color); // may be null
for (Entry<String, Object> entry : this.fields.entrySet())
{
object.put(entry.getKey(), entry.getValue());
}
return object.toString();
}
}
代码示例来源:origin: sebfz1/wicket-jquery-ui
/**
* Return the JSON representation of this object<br>
* This needs to be done manually because of the xField and yField that are not properly converted (camel case issue)
*
* @return the JSON string
*/
@Override
public String toJSONString()
{
JSONObject object = new JSONObject(this);
object.put("xField", this.xField);
object.put("yField", this.yField);
return object.toString();
}
代码示例来源:origin: org.wicketstuff/wicket-gchart
/**
* Create the load statement of the chart lib with package, language and
* Maps API key declaration as defined by the chart and its
* {@link ChartType}.
*
* @return Onle line load statement to be included in a JavaScript.
*/
protected String createLoaderStatement() {
StringBuilder sb = new StringBuilder();
// Load the Visualization API and the package.
JSONObject packageDecl = new JSONObject();
JSONArray packages = new JSONArray();
packages.put(typeModel.getObject().getLoadPackage());
packageDecl.put("packages", packages);
packageDecl.put("language", getLocale().getLanguage());
if (mapsApiKey != null) {
packageDecl.put("mapsApiKey", mapsApiKey);
}
sb.append("google.charts.load('current', ").append(packageDecl.toString()).append(");").append("\n");
return sb.toString();
}
代码示例来源:origin: sebfz1/wicket-jquery-ui
public String toString(JQueryAjaxBehavior behavior)
{
JSONObject object = this.toJSONObject();
if (this.isEnabled() && behavior != null)
{
object.put("click", new JSONFunction(behavior.getCallbackFunction()));
}
return object.toString();
}
代码示例来源:origin: com.googlecode.wicket-jquery-ui/wicket-kendo-ui
public String toString(JQueryAjaxBehavior behavior)
{
JSONObject object = this.toJSONObject();
if (this.isEnabled() && behavior != null)
{
object.put("click", new JSONFunction(behavior.getCallbackFunction()));
}
return object.toString();
}
代码示例来源:origin: org.wicketstuff/wicketstuff-tinymce4
private void respond(Iterator<String> words, String cmd, String id)
{
JSONArray array = new JSONArray();
if (words != null)
{
while (words.hasNext())
array.put(words.next());
}
JSONObject response = new JSONObject();
try
{
response.put("id", id);
response.put("error", (String)null);
response.put("result", array);
setResponse(response.toString());
}
catch (JSONException e)
{
jsonError("Failed to construct response");
}
}
代码示例来源:origin: org.wicketstuff/wicketstuff-tinymce3
private void respond(Iterator<String> words, String cmd, String id)
{
JSONArray array = new JSONArray();
if (words != null)
{
while (words.hasNext())
array.put(words.next());
}
JSONObject response = new JSONObject();
try
{
response.put("id", id);
response.put("error", (String)null);
response.put("result", array);
setResponse(response.toString());
}
catch (JSONException e)
{
jsonError("Failed to construct response");
}
}
代码示例来源:origin: OrienteerBAP/Orienteer
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
response.render(CssHeaderItem.forReference(ODateTimeField.ORIENTEER_DATE_FIELD_CSS));
response.render(JavaScriptHeaderItem.forReference(PICKER_JS));
response.render(OnDomReadyHeaderItem.forScript(String.format("initJQDatepicker('%s', %s)", dateField.getMarkupId(),
getDatePickerParams().toString())));
}
内容来源于网络,如有侵权,请联系作者删除!