本文整理汇总了Java中org.json.JSONStringer.toString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONStringer.toString方法的具体用法?Java JSONStringer.toString怎么用?Java JSONStringer.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONStringer
的用法示例。
在下文中一共展示了JSONStringer.toString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toJSONString
import org.json.JSONStringer; //导入方法依赖的package包/类
/**
* @param <T>
* @param object
* @return
*/
public static String toJSONString(Object object) {
JSONStringer stringer = new JSONStringer();
try {
if (object instanceof JSONSerializable) {
stringer.object();
((JSONSerializable) object).toJSON(stringer);
stringer.endObject();
} else if (object != null) {
Class<?> clazz = object.getClass();
// stringer.key(clazz.getSimpleName());
JSONUtil.writeFieldValue(stringer, clazz, object);
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
return (stringer.toString());
}
示例2: toJSON
import org.json.JSONStringer; //导入方法依赖的package包/类
public String toJSON(List<User> users) throws JSONException {
try{
JSONStringer jsonStringer = new JSONStringer();
jsonStringer.object().key("lista").array().object().key("user").array();
for (User user:users){
jsonStringer.object();
jsonStringer.key("cpf").value(user.getCpf());
jsonStringer.key("name").value(user.getName());
jsonStringer.key("phone").value(user.getPhone());
jsonStringer.key("email").value(user.getEmail());
jsonStringer.key("company").value(user.getCompany());
jsonStringer.key("birthdate").value(user.getBirthdate());
jsonStringer.key("url").value(user.getUrl());
jsonStringer.key("location").value(user.getLocation());
jsonStringer.key("photo").value(user.getPhoto());
jsonStringer.endObject();
}
jsonStringer.endArray().endObject().endArray().endObject();
return jsonStringer.toString();
} catch (JSONException e){
return null;
}
}
示例3: toJSONString
import org.json.JSONStringer; //导入方法依赖的package包/类
@Override
public String toJSONString() {
JSONStringer stringer = new JSONStringer();
try
{
stringer.object();
toJSONString(stringer);
stringer.endObject();
}
catch (JSONException e)
{
throw new RuntimeException("Failed to serialize " + this, e);
// System.exit(-1);
}
return stringer.toString();
}
示例4: toJSONString
import org.json.JSONStringer; //导入方法依赖的package包/类
@Override
public String toJSONString() {
JSONStringer stringer = new JSONStringer();
try {
stringer.object();
super.toJSONString(stringer);
stringer.key(Members.EXECUTE_LIST.name()).array();
for (AbstractPlanNode node : m_list) {
stringer.value(node.getPlanNodeId().intValue());
}
stringer.endArray(); //end execution list
stringer.endObject(); //end PlanNodeList
} catch (JSONException e) {
// HACK ugly ugly to make the JSON handling
// in QueryPlanner generate a JSONException for a plan we know
// here that we can't serialize. Making this method throw
// JSONException pushes that exception deep into the bowels of
// Volt with no good place to catch it and handle the error.
// Consider this the coward's way out.
throw new RuntimeException("Failed to serialize PlanNodeList", e);
// return "This JSON error message is a lie";
}
return stringer.toString();
}
示例5: toJSONString
import org.json.JSONStringer; //导入方法依赖的package包/类
public String toJSONString(Database catalog_db) {
JSONStringer stringer = new JSONStringer();
try {
stringer.object();
this.toJSONString(stringer, catalog_db);
stringer.endObject();
} catch (JSONException e) {
e.printStackTrace();
System.exit(-1);
}
return stringer.toString();
}
示例6: toJSONString
import org.json.JSONStringer; //导入方法依赖的package包/类
/**
*
*/
@Override
public String toJSONString() {
JSONStringer stringer = new JSONStringer();
try {
stringer.object();
this.toJSONString(stringer);
stringer.endObject();
} catch (JSONException e) {
e.printStackTrace();
System.exit(-1);
}
return stringer.toString();
}
示例7: toJSONString
import org.json.JSONStringer; //导入方法依赖的package包/类
public String toJSONString() {
JSONStringer stringer = new JSONStringer();
try {
stringer.object();
toJSONString(stringer);
stringer.endObject();
} catch (JSONException e) {
e.printStackTrace();
return null;
}
return stringer.toString();
}
示例8: toJSONString
import org.json.JSONStringer; //导入方法依赖的package包/类
@Override
public String toJSONString() {
JSONStringer stringer = new JSONStringer();
try {
stringer.object();
this.toJSONString(stringer);
stringer.endObject();
} catch (JSONException e) {
e.printStackTrace();
System.exit(-1);
}
return stringer.toString();
}
示例9: createJsonString
import org.json.JSONStringer; //导入方法依赖的package包/类
/**
* @param key
* @param value
* @return
* @throws
* @Title: createJsonString
* @Description: 生成json字符串
* @return: String
*/
public static String createJsonString(String key, JSONArray value) {
JSONStringer jsonStringer = new JSONStringer();
try {
jsonStringer.object().key(key).value(value).endObject();
} catch (JSONException e) {
e.printStackTrace();
}
return jsonStringer.toString();
}
示例10: toJson
import org.json.JSONStringer; //导入方法依赖的package包/类
public CharSequence toJson() {
try {
JSONStringer writer = new JSONStringer();
writer.object();
Json.writeObject(writer, "minimumInputLength", minimumInputLength);
Json.writeObject(writer, "minimumResultsForSearch", minimumResultsForSearch);
Json.writeObject(writer, "maximumSelectionSize", maximumSelectionSize);
Json.writeObject(writer, "placeholder", placeholder);
Json.writeObject(writer, "allowClear", allowClear);
Json.writeObject(writer, "multiple", multiple);
Json.writeObject(writer, "closeOnSelect", closeOnSelect);
Json.writeFunction(writer, "id", id);
Json.writeFunction(writer, "matcher", matcher);
Json.writeFunction(writer, "tokenizer", tokenizer);
Json.writeFunction(writer, "sortResults", sortResults);
Json.writeFunction(writer, "formatSelection", formatSelection);
Json.writeFunction(writer, "formatResult", formatResult);
Json.writeFunction(writer, "formatNoMatches", formatNoMatches);
Json.writeFunction(writer, "formatInputTooShort", formatInputTooShort);
Json.writeFunction(writer, "formatResultCssClass", formatResultCssClass);
Json.writeFunction(writer, "formatSelectionTooBig", formatSelectionTooBig);
Json.writeFunction(writer, "formatLoadMore", formatLoadMore);
Json.writeFunction(writer, "formatSearching", formatSearching);
Json.writeFunction(writer, "escapeMarkup", escapeMarkup);
Json.writeFunction(writer, "createSearchChoice", createSearchChoice);
Json.writeFunction(writer, "initSelection", initSelection);
Json.writeFunction(writer, "query", query);
Json.writeObject(writer, "width", width);
Json.writeObject(writer, "openOnEnter", openOnEnter);
Json.writeFunction(writer, "containerCss", containerCss);
Json.writeObject(writer, "containerCssClass", containerCssClass);
Json.writeFunction(writer, "dropdownCss", dropdownCss);
Json.writeObject(writer, "dropdownCssClass", dropdownCssClass);
Json.writeObject(writer, "separator", separator);
Json.writeObject(writer, "tokenSeparators", tokenSeparators);
Json.writeObject(writer, "dropdownAutoWidth", dropdownAutoWidth);
if (ajax != null) {
writer.key("ajax");
ajax.toJson(writer);
}
Json.writeFunction(writer, "data", data);
Json.writeFunction(writer, "tags", tags);
writer.endObject();
return writer.toString();
} catch (JSONException e) {
throw new RuntimeException("Could not convert Select2 settings object to Json", e);
}
}