當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonObject.set方法代碼示例

本文整理匯總了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);
	}
	
}
 
開發者ID:rodrigoEclipsa,項目名稱:excelToApp,代碼行數:29,代碼來源:ExcelManager.java

示例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;
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:18,代碼來源:Settings.java

示例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;
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:25,代碼來源:MessagingIdentity.java

示例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;
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:19,代碼來源:Util.java

示例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;
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:18,代碼來源:Settings.java

示例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;
	}
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:32,代碼來源:MessagingPanel.java

示例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;
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:12,代碼來源:MessagingOptions.java

示例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;
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:29,代碼來源:Message.java

示例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);
	}
}
 
開發者ID:Col-E,項目名稱:Recaf,代碼行數:42,代碼來源:Config.java

示例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);
	}
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:59,代碼來源:MessagingPanel.java

示例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();
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:51,代碼來源:ZCashClientCaller.java


注:本文中的com.eclipsesource.json.JsonObject.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。