下面列出了org.json.JSONWriter#key ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void toJSONWriter(JSONWriter writer) {
writer.key("ledger_index");
writer.value(sequence.toJSON());
writer.key("total_coins");
writer.value(totalXRP.toString(10));
writer.key("parent_hash");
writer.value(previousLedger.toJSON());
writer.key("transaction_hash");
writer.value(transactionHash.toJSON());
writer.key("account_hash");
writer.value(stateHash.toJSON());
writer.key("close_time");
writer.value(closeTime.toJSON());
writer.key("parent_close_time");
writer.value(parentCloseTime.toJSON());
writer.key("close_time_resolution");
writer.value(closeResolution.toJSON());
writer.key("close_flags");
writer.value(closeFlags.toJSON());
}
public void toJSONWriter(JSONWriter writer) {
writer.key("ledger_index");
writer.value(sequence.toJSON());
writer.key("total_coins");
writer.value(totalXRP.toString(10));
writer.key("parent_hash");
writer.value(previousLedger.toJSON());
writer.key("transaction_hash");
writer.value(transactionHash.toJSON());
writer.key("account_hash");
writer.value(stateHash.toJSON());
writer.key("close_time");
writer.value(closeTime.toJSON());
writer.key("parent_close_time");
writer.value(parentCloseTime.toJSON());
writer.key("close_time_resolution");
writer.value(closeResolution.toJSON());
writer.key("close_flags");
writer.value(closeFlags.toJSON());
}
public void toJSONWriter(JSONWriter writer) {
writer.key("ledger_index");
writer.value(sequence.toJSON());
writer.key("total_coins");
writer.value(totalXRP.toString(10));
writer.key("parent_hash");
writer.value(previousLedger.toJSON());
writer.key("transaction_hash");
writer.value(transactionHash.toJSON());
writer.key("account_hash");
writer.value(stateHash.toJSON());
writer.key("close_time");
writer.value(closeTime.toJSON());
writer.key("parent_close_time");
writer.value(parentCloseTime.toJSON());
writer.key("close_time_resolution");
writer.value(closeResolution.toJSON());
writer.key("close_flags");
writer.value(closeFlags.toJSON());
}
public String toJSON() {
StringWriter writer = new StringWriter();
JSONWriter json = new JSONWriter(writer);
json.object();
for (String name : this.getFieldNames()) {
String value = this.getValue(name);
if (value != null && value.length() > 0) {
json.key(name);
json.value(value);
}
}
json.endObject();
return writer.toString();
}
@Override
public void toJson(Project choice, JSONWriter writer) throws JSONException {
writer.key("id").value(choice.getId());
writer.key("name");
writer.value(HtmlEscape.escapeHtml5(choice.getName()));
}
/**
* Writes a key/value pair into the {@code writer} if the value is not {@code null}
*
* @param writer
* json writer
* @param key
* key
* @param value
* value
* @throws JSONException
*/
public static void writeObject(JSONWriter writer, String key, Object value) throws JSONException {
if (value != null) {
writer.key(key);
writer.value(value);
}
}