本文整理汇总了Java中com.eclipsesource.json.JsonObject.set方法的典型用法代码示例。如果您正苦于以下问题:Java JsonObject.set方法的具体用法?Java JsonObject.set怎么用?Java JsonObject.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.eclipsesource.json.JsonObject
的用法示例。
在下文中一共展示了JsonObject.set方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setValidTypeJson
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
/**
* asigna valores JSON validos a un jsonObject
* @param cellRef
* @param jsonObject
* @param value
*/
private void setValidTypeJson(String cellRef,JsonObject jsonObject, String value)
{
int jsonValidType = jsonValidType(value);
if(jsonValidType == JSON_STRING)
{
jsonObject.set(cellRef, value);
}
else if(jsonValidType == JSON_NUMBER)
{
jsonObject.set(cellRef, Double.parseDouble(value));
}
else if(jsonValidType == JSON_BOOLEAN)
{
jsonObject.set(cellRef, Boolean.getBoolean(value));
}
else
{
jsonObject.set(cellRef, value);
}
}
示例2: write
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
public static boolean write() {
FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");
JsonObject json = new JsonObject();
for (Map.Entry<String, Setting> entry : settings.entrySet()) {
json.set(entry.getKey(), entry.getValue().toJson());
}
try {
Writer writer = fileHandle.writer(false);
json.writeTo(writer, WriterConfig.PRETTY_PRINT);
writer.close();
} catch (Exception e) {
Log.error("Failed to write settings", e);
fileHandle.delete();
return false;
}
return true;
}
示例3: toJSONObject
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
public JsonObject toJSONObject(boolean bForMesagingProtocol)
{
JsonObject obj = new JsonObject();
obj.set("nickname", nonNull(nickname));
obj.set("sendreceiveaddress", nonNull(sendreceiveaddress));
obj.set("senderidaddress", nonNull(senderidaddress));
obj.set("firstname", nonNull(firstname));
obj.set("middlename", nonNull(middlename));
obj.set("surname", nonNull(surname));
obj.set("email", nonNull(email));
obj.set("streetaddress", nonNull(streetaddress));
obj.set("facebook", nonNull(facebook));
obj.set("twitter", nonNull(twitter));
if (!bForMesagingProtocol)
{
obj.set("isanonymous", isAnonymous);
obj.set("isgroup", isGroup);
obj.set("threadid", nonNull(threadID));
}
return obj;
}
示例4: getJsonErrorMessage
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
public static JsonObject getJsonErrorMessage(String info)
throws IOException
{
JsonObject jInfo = new JsonObject();
// Error message here comes from ZCash 1.0.7+ and is like:
//zcash-cli getinfo
//error code: -28
//error message:
//Loading block index...
LineNumberReader lnr = new LineNumberReader(new StringReader(info));
int errCode = Integer.parseInt(lnr.readLine().substring(11).trim());
jInfo.set("code", errCode);
lnr.readLine();
jInfo.set("message", lnr.readLine().trim());
return jInfo;
}
示例5: write
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
public static boolean write() {
FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");
JsonObject json = new JsonObject();
for (Map.Entry<String, Setting> entry : settings.entrySet()) {
json.set(entry.getKey(), entry.getValue().toJson());
}
try {
Writer writer = fileHandle.writer(false);
json.writeTo(writer, WriterConfig.PRETTY_PRINT);
writer.close();
} catch (Exception e) {
Log.error("Failed to write settings", e);
fileHandle.delete();
return false;
}
return true;
}
示例6: sendIdentityMessageTo
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
public void sendIdentityMessageTo(MessagingIdentity contactIdentity)
throws InterruptedException, IOException, WalletCallException
{
// Only a limited set of values is sent over the wire, due tr the limit of 330
// characters. // TODO: use protocol versions with larger messages
MessagingIdentity ownIdentity = this.messagingStorage.getOwnIdentity();
JsonObject innerIDObject = new JsonObject();
innerIDObject.set("nickname", ownIdentity.getNickname());
innerIDObject.set("firstname", ownIdentity.getFirstname());
innerIDObject.set("surname", ownIdentity.getSurname());
innerIDObject.set("senderidaddress", ownIdentity.getSenderidaddress());
innerIDObject.set("sendreceiveaddress", ownIdentity.getSendreceiveaddress());
JsonObject outerObject = new JsonObject();
outerObject.set("zenmessagingidentity", innerIDObject);
String identityString = outerObject.toString();
// Check and send the messaging identity as a message
if (identityString.length() <= 330) // Protocol V1 restriction
{
this.sendMessage(identityString, contactIdentity);
} else
{
JOptionPane.showMessageDialog(
this.parentFrame,
"The size of your messaging identity is unfortunately too large to be sent\n" +
"as a message. Your contact will have to import your messaging identity\n" +
"manaully from a json file...",
"Messaging identity size is too large!", JOptionPane.ERROR_MESSAGE);
return;
}
}
示例7: toJSONObject
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
public JsonObject toJSONObject()
{
JsonObject obj = new JsonObject();
obj.set("automaticallyaddusersifnotexplicitlyimported",
this.automaticallyAddUsersIfNotExplicitlyImported);
obj.set("amounttosend", this.amountToSend);
obj.set("transactionfee", this.transactionFee);
return obj;
}
示例8: toJSONObject
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
public JsonObject toJSONObject(boolean forWireProtocol)
{
JsonObject obj = new JsonObject();
if (this.isAnonymous())
{
obj.set("ver", version);
obj.set("message", nonNull(message));
obj.set("threadid", nonNull(threadID));
} else
{
obj.set("ver", version);
obj.set("from", nonNull(from));
obj.set("message", nonNull(message));
obj.set("sign", nonNull(sign));
}
if (!forWireProtocol)
{
obj.set("transactionID", nonNull(transactionID));
obj.set("time", this.time.getTime());
obj.set("direction", this.direction.toString());
obj.set("verification", this.verification.toString());
obj.set("isanonymous", isAnonymous);
}
return obj;
}
示例9: save
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
/**
* Save current settings to configuration.
*/
public void save() {
try {
if (!confFile.exists() && !confFile.createNewFile()) {
// Return if config file cannot be found and cannot be created.
return;
}
JsonObject json = Json.object();
for (Field field : this.getClass().getDeclaredFields()) {
// Skip private and static fields.
int mod = field.getModifiers();
if (Modifier.isPrivate(mod) || Modifier.isStatic(mod)) {
continue;
}
// Access via reflection, add value to json object.
field.setAccessible(true);
String name = field.getName();
Object value = field.get(this);
if (value instanceof Boolean) {
json.set(name, (boolean) value);
} else if (value instanceof Integer) {
json.set(name, (int) value);
} else if (value instanceof String) {
json.set(name, (String) value);
} else {
JsonValue converted = convert(field.getType(), value);
if (converted != null) {
json.set(name, converted);
}
}
}
// Write json to file
StringWriter w = new StringWriter();
json.writeTo(w, WriterConfig.PRETTY_PRINT);
Files.writeFile(confFile.getAbsolutePath(), w.toString());
} catch (Exception e) {
Recaf.INSTANCE.logging.error(e);
}
}
示例10: addMessagingGroup
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
public void addMessagingGroup()
{
try
{
CreateGroupDialog cgd = new CreateGroupDialog(
this, this.parentFrame, this.messagingStorage, this.errorReporter, this.clientCaller);
cgd.setVisible(true);
if (!cgd.isOKPressed())
{
return;
}
// So a group is created - we need to ask the user if he wishes to send an identity message
MessagingIdentity createdGroup = cgd.getCreatedGroup();
int sendIDChoice = JOptionPane.showConfirmDialog(
this.parentFrame,
"Do you wish to send a limited sub-set of your contact details to group\n" +
createdGroup.getDiplayString() + "\n" +
"This will allow other group members to know your messaging identity.",
"Send contact details?", JOptionPane.YES_NO_OPTION);
// TODO: code duplication with import
if (sendIDChoice == JOptionPane.YES_OPTION)
{
// Only a limited set of values is sent over the wire, due tr the limit of 330
// characters. // TODO: use protocol versions with larger messages
MessagingIdentity ownIdentity = this.messagingStorage.getOwnIdentity();
JsonObject innerIDObject = new JsonObject();
innerIDObject.set("nickname", ownIdentity.getNickname());
innerIDObject.set("firstname", ownIdentity.getFirstname());
innerIDObject.set("surname", ownIdentity.getSurname());
innerIDObject.set("senderidaddress", ownIdentity.getSenderidaddress());
innerIDObject.set("sendreceiveaddress", ownIdentity.getSendreceiveaddress());
JsonObject outerObject = new JsonObject();
outerObject.set("zenmessagingidentity", innerIDObject);
String identityString = outerObject.toString();
// Check and send the messaging identity as a message
if (identityString.length() <= 330) // Protocol V1 restriction
{
this.sendMessage(identityString, createdGroup);
} else
{
JOptionPane.showMessageDialog(
this.parentFrame,
"The size of your messaging identity is unfortunately too large to be sent\n" +
"as a message.",
"Messaging identity size is too large!", JOptionPane.ERROR_MESSAGE);
return;
}
}
} catch (Exception ex)
{
this.errorReporter.reportError(ex, false);
}
}
示例11: sendMessage
import com.eclipsesource.json.JsonObject; //导入方法依赖的package包/类
public synchronized String sendMessage(String from, String to, double amount, double fee, String memo)
throws WalletCallException, IOException, InterruptedException
{
String hexMemo = Util.encodeHexString(memo);
JsonObject toArgument = new JsonObject();
toArgument.set("address", to);
if (hexMemo.length() >= 2)
{
toArgument.set("memo", hexMemo.toString());
}
DecimalFormatSymbols decSymbols = new DecimalFormatSymbols(Locale.ROOT);
// TODO: The JSON Builder has a problem with double values that have no fractional part
// it serializes them as integers that ZCash does not accept. This will work with the
// fractional amounts always used for messaging
toArgument.set("amount", new DecimalFormat("########0.00######", decSymbols).format(amount));
JsonArray toMany = new JsonArray();
toMany.add(toArgument);
String toManyArrayStr = toMany.toString();
String[] sendCashParameters = new String[]
{
this.zcashcli.getCanonicalPath(), "z_sendmany", wrapStringParameter(from),
wrapStringParameter(toManyArrayStr),
// Default min confirmations for the input transactions is 1
"1",
// transaction fee
new DecimalFormat("########0.00######", decSymbols).format(fee)
};
// Create caller to send cash
CommandExecutor caller = new CommandExecutor(sendCashParameters);
String strResponse = caller.execute();
if (strResponse.trim().toLowerCase(Locale.ROOT).startsWith("error:") ||
strResponse.trim().toLowerCase(Locale.ROOT).startsWith("error code:"))
{
throw new WalletCallException("Error response from wallet: " + strResponse);
}
Log.info("Sending cash message with the following command: " +
sendCashParameters[0] + " " + sendCashParameters[1] + " " +
sendCashParameters[2] + " " + sendCashParameters[3] + " " +
sendCashParameters[4] + " " + sendCashParameters[5] + "." +
" Got result: [" + strResponse + "]");
return strResponse.trim();
}