本文整理匯總了Java中net.sf.json.JSONObject.containsKey方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.containsKey方法的具體用法?Java JSONObject.containsKey怎麽用?Java JSONObject.containsKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.sf.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.containsKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: deserialize
import net.sf.json.JSONObject; //導入方法依賴的package包/類
@Override
public List<Object> deserialize(ByteBuffer ser) {
String jsonStr = null;
if (ser.hasArray()) {
int base = ser.arrayOffset();
jsonStr = new String(ser.array(), base + ser.position(), ser.remaining());
} else {
jsonStr = new String(Utils.toByteArray(ser), UTF8_CHARSET);
}
JSONObject jsonObject = JSONObject.fromObject(jsonStr);
Values values = new Values();
for (String outputField : outputFields) {
if("jsonBody".equals(outputField)) {
values.add(jsonStr);
} else {
if(!jsonObject.containsKey(outputField)) {
JSONObject rcMsgpara = JSONObject.fromObject(jsonObject.get("rc_msg_para"));
values.add(rcMsgpara.get(outputField));
} else {
values.add(jsonObject.get(outputField));
}
}
}
return values;
}
示例2: UserData
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public UserData(JSONObject userData) {
if (userData.containsKey("userId")) {
this.userId = userData.getString("userId");
}
if (userData.containsKey("userRealName")) {
this.userRealName = userData.getString("userRealName");
}
if (userData.containsKey("userGroupTopId")) {
this.userGroupTopId = userData.getString("userGroupTopId");
}
if (userData.containsKey("userRole")) {
this.userRole = userData.getInt("userRole");
}
if (userData.containsKey("userImgUrl")) {
this.userImgUrl = userData.getString("userImgUrl");
}
}
示例3: extractErrorMessage
import net.sf.json.JSONObject; //導入方法依賴的package包/類
@Override
protected String extractErrorMessage(String response) {
if (response != null && !response.isEmpty()) {
try {
JSON jsonResponse = JSONSerializer.toJSON(response, new JsonConfig());
if (jsonResponse instanceof JSONObject) {
JSONObject object = (JSONObject) jsonResponse;
JSONObject errorObj = object.getJSONObject("error");
if (errorObj.containsKey("message")) {
return errorObj.getString("message");
}
}
} catch (JSONException ex) {
log.debug("Cannot parse JSON error response: " + response);
}
}
return response;
}
示例4: onPreInitialize
import net.sf.json.JSONObject; //導入方法依賴的package包/類
@Override
public void onPreInitialize(AGContext context, JSONObject initArgs) {
Log.d(TAG, "onPreInitialize(%s)", context.hashCode());
ArbitraryGenProcessor processor = context.getProcessor("javaCodeEngine");
if (processor instanceof JavaCodeAGEngine) {
JavaCodeAGEngine engine = (JavaCodeAGEngine) processor;
AGAnnotationWrapper annWrapper = new AGAnnotationWrapper();
annWrapper.addAnnotationProcessor(new IPCInvokeTaskProcessor());
engine.addTypeDefWrapper(annWrapper);
JSONObject javaCodeEngine = initArgs.getJSONObject("javaCodeEngine");
if (javaCodeEngine != null) {
if (!javaCodeEngine.containsKey("ruleFile") && !javaCodeEngine.containsKey("rule")) {
javaCodeEngine.put("rule", "${project.projectDir}/src/main/java/*.java");
}
}
}
}
示例5: UserGroupData
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public UserGroupData(JSONObject userGroupData) {
if (userGroupData.containsKey("userGroupId")) {
this.userGroupId = userGroupData.getString("userGroupId");
}
if (userGroupData.containsKey("userGroupName")) {
this.userGroupName = userGroupData.getString("userGroupName");
}
}
示例6: findMosaicFeeInformationByNIS
import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
* Find mosaic fee information by NIS.
*
* @param mosaicId the mosaic id
* @return the mosaic fee information
*/
public static MosaicFeeInformation findMosaicFeeInformationByNIS(MosaicId mosaicId){
String host = "alice2.nem.ninja";
String port = "7890";
NemNetworkResponse queryResult = NetworkUtils.get("http://"+host+":"+port+NemAppsLibGlobals.URL_NAMESPACE_MOSAIC_DEFINITION_PAGE + "?namespace=" + mosaicId.getNamespaceId().toString());
JSONObject json = JSONObject.fromObject(queryResult.getResponse());
if(json==null || !json.containsKey("data") || json.getJSONArray("data").size()==0){
return null;
}
JSONArray array = json.getJSONArray("data");
for(int i=0;i<array.size();i++){
JSONObject item = array.getJSONObject(i);
JSONObject mosaic = item.getJSONObject("mosaic");
JSONObject id = mosaic.getJSONObject("id");
if(mosaicId.getName().equals(id.getString("name"))){
JSONArray properties = mosaic.getJSONArray("properties");
String initialSupply = "";
String divisibility = "";
for(int j=0;j<properties.size();j++){
JSONObject property = properties.getJSONObject(j);
if("initialSupply".equals(property.getString("name"))){
initialSupply = property.getString("value");
} else if("divisibility".equals(property.getString("name"))){
divisibility = property.getString("value");
}
}
if(!"".equals(initialSupply) && !"".equals(divisibility)){
return new MosaicFeeInformation(Supply.fromValue(Long.valueOf(initialSupply)), Integer.valueOf(divisibility));
}
}
}
return null;
}
示例7: configure
import net.sf.json.JSONObject; //導入方法依賴的package包/類
@Override
public boolean configure(StaplerRequest staplerRequest, JSONObject json) throws FormException {
// to persist global configuration information,
// set that to properties and call save().
//System.out.println(json.toString());
if(json.containsKey("logPollingFreq")) {
logPollingFreq = json.getInt("logPollingFreq");
}
else {
logPollingFreq = 15;
}
save();
return true; // indicate that everything is good so far
}
示例8: hasFormDataKey
import net.sf.json.JSONObject; //導入方法依賴的package包/類
protected String hasFormDataKey(JSONObject formData, GlobalConfig globalConfig) {
String instanceName;
if (formData.containsKey("sonarInstancesName")) {
instanceName = formData.getString("sonarInstancesName");
} else {
instanceName = globalConfig.fetchListOfGlobalConfigData().get(0).getName();
}
return instanceName;
}
示例9: findMosaicFeeInformationByNIS
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public static MosaicFeeInformation findMosaicFeeInformationByNIS(MosaicId mosaicId){
String queryResult = HttpClientUtils.get(Constants.URL_NAMESPACE_MOSAIC_DEFINITION_PAGE + "?namespace=" + mosaicId.getNamespaceId().toString());
JSONObject json = JSONObject.fromObject(queryResult);
if(json==null || !json.containsKey("data") || json.getJSONArray("data").size()==0){
return null;
}
JSONArray array = json.getJSONArray("data");
for(int i=0;i<array.size();i++){
JSONObject item = array.getJSONObject(i);
JSONObject mosaic = item.getJSONObject("mosaic");
JSONObject id = mosaic.getJSONObject("id");
if(mosaicId.getName().equals(id.getString("name"))){
JSONArray properties = mosaic.getJSONArray("properties");
String initialSupply = "";
String divisibility = "";
for(int j=0;j<properties.size();j++){
JSONObject property = properties.getJSONObject(j);
if("initialSupply".equals(property.getString("name"))){
initialSupply = property.getString("value");
} else if("divisibility".equals(property.getString("name"))){
divisibility = property.getString("value");
}
}
if(!"".equals(initialSupply) && !"".equals(divisibility)){
return new MosaicFeeInformation(Supply.fromValue(Long.valueOf(initialSupply)), Integer.valueOf(divisibility));
}
}
}
return null;
}
示例10: main
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public static void main(String[] args) {
DefaultSetting.setDefaultNetwork();
if(args.length==0){
OutputMessage.error("please enter parameter");
return;
}
Map<String, String> params = parseParamsToMap(args);
if(params==null){
return;
}
// set host and port
DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), null);
// get multisig public key
String multisigPublicKey = KeyConvertor.getPublicKeyFromAddress(params.get("multisigAddress"));
if(StringUtils.isEmpty(multisigPublicKey)){
OutputMessage.error("unable to find multisig public Key from multisig address");
return;
}
// send transaction
String innerTransactionHash = params.get("innerTransactionHash");
String cosignatoryPublicKey = params.get("cosignatoryPublicKey");
String cosignatoryPrivateKey = params.get("cosignatoryPrivateKey");
String multisigAddress = params.get("multisigAddress");
String fee = params.get("fee");
CosignMultisigTransaction tx = new CosignMultisigTransaction(cosignatoryPublicKey, cosignatoryPrivateKey, multisigAddress, multisigPublicKey, innerTransactionHash);
JSONObject result = JSONObject.fromObject(tx.send_v2(fee));
if(result.containsKey("message") && "SUCCESS".equals(result.getString("message"))){
String transactionHash = result.getJSONObject("transactionHash").getString("data");
OutputMessage.initCosignTransactionMessage("success", transactionHash);
} else {
OutputMessage.error(result.getString("message"));
}
}
示例11: UserData
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public UserData(JSONObject userData) {
if (userData.containsKey("userId")) {
this.userId = userData.getString("userId");
}
}
示例12: main
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public static void main(String[] args) {
DefaultSetting.setDefaultNetwork();
if(args.length==0){
OutputMessage.error("please enter parameter");
return;
}
Map<String, String> params = parseParamsToMap(args);
if(params==null){
return;
}
// set host and port
DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), null);
// check if owns the mosaic
String address = params.get("address");
String mosaicName = params.get("mosaicName");
String mosaicQuantity = params.get("mosaicQuantity");
MosaicId mosaicId = null;
Quantity quantity = null;
if(mosaicName!=null && mosaicQuantity!=null){
mosaicId = MosaicId.parse(mosaicName);
MosaicFeeInformation mosaicFeeInformation = NISQuery.findMosaicFeeInformationByNIS(mosaicId);
String validateMessage = validateMosaic(address, mosaicName, mosaicQuantity, mosaicFeeInformation);
if(validateMessage!=null) {
OutputMessage.error(validateMessage);
return;
}
Double mosaicQuantityDouble = Double.valueOf(mosaicQuantity);
int divisibility = mosaicFeeInformation.getDivisibility();
Double mosaicQuantityAddDivisibility = Double.valueOf(mosaicQuantityDouble.doubleValue() * Math.pow(10, divisibility));
quantity = Quantity.fromValue(mosaicQuantityAddDivisibility.longValue());
}
// send transaction
String publicKey = params.get("publicKey");
String privateKey = params.get("privateKey");
long amount = Long.valueOf(params.get("amount")).longValue();
String recipient = params.get("recipient");
String message = params.get("message");
String fee = params.get("fee");
InitTransaction tx = new InitTransaction(publicKey, privateKey);
JSONObject result = JSONObject.fromObject(tx.send_v2(recipient, amount, message, mosaicId, quantity, fee));
if(result.containsKey("message") && "SUCCESS".equals(result.getString("message"))){
String transactionHash = result.getJSONObject("transactionHash").getString("data");
OutputMessage.initTransactionMessage("success", transactionHash);
} else {
OutputMessage.error(result.getString("message"));
}
}
示例13: monitorCosignUnconfirmed
import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
* monitor multisig unconfirmed (cosign)
* @param result
* @return
*/
private void monitorCosignUnconfirmed(String result){
JSONObject json = null;
try {
json = JSONObject.fromObject(result);
} catch (Exception ex) {
return;
}
if(!json.containsKey("otherHash")
|| !json.containsKey("otherAccount")
|| json.getLong("type")!=Constants.TX_TYPE_COSIGN_MULTISIG){
return;
}
long timeStamp = json.getLong("timeStamp");
String innerTransactionHash = json.getJSONObject("otherHash").getString("data");
String otherAccount = json.getString("otherAccount");
String cosignAddress = KeyConvertor.getAddressFromPublicKey(json.getString("signer"));
if(!otherAccount.equals(this.address)){
return;
}
if(!outCosignedMap.containsKey(innerTransactionHash)){
return;
}
JSONObject outJSON = outCosignedMap.get(innerTransactionHash);
JSONObject outCosignAccount = new JSONObject();
JSONArray outCosignAccountArray = outJSON.getJSONArray("cosignAccount");
outCosignAccount.put("address", cosignAddress);
outCosignAccount.put("date", DateUtils.nemToRealDateStr(timeStamp));
outCosignAccountArray.add(outCosignAccount);
if(outCosignAccountArray.size()>=outJSON.getInt("minCosignatories")){
outCosignedMap.remove(innerTransactionHash);
return;
}
JSONArray outUnsignedAccountArray = outJSON.getJSONArray("unsignedAccount");
int removeIndex = -1;
for(int i=0;i<outUnsignedAccountArray.size();i++){
if(outUnsignedAccountArray.getJSONObject(i).getString("address").equals(cosignAddress)){
removeIndex = i;
break;
}
}
if(removeIndex!=-1) {
outUnsignedAccountArray.remove(removeIndex);
}
outJSON.put("cosignAccount", outCosignAccountArray);
outJSON.put("unsignedAccount", outUnsignedAccountArray);
outCosignedMap.put(innerTransactionHash, outJSON);
System.out.println(outJSON.toString());
}
示例14: main
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public static void main(String[] args) {
DefaultSetting.setDefaultNetwork();
if(args.length==0){
OutputMessage.error("please enter parameter");
return;
}
Map<String, String> params = parseParamsToMap(args);
if(params==null){
return;
}
// set host and port
DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), null);
// check if owns the mosaic
String address = params.get("multisigAddress");
String mosaicName = params.get("mosaicName");
String mosaicQuantity = params.get("mosaicQuantity");
MosaicId mosaicId = null;
Quantity quantity = null;
if(mosaicName!=null && mosaicQuantity!=null){
mosaicId = MosaicId.parse(mosaicName);
MosaicFeeInformation mosaicFeeInformation = NISQuery.findMosaicFeeInformationByNIS(mosaicId);
String validateMessage = validateMosaic(address, mosaicName, mosaicQuantity, mosaicFeeInformation);
if(validateMessage!=null) {
OutputMessage.error(validateMessage);
return;
}
Double mosaicQuantityDouble = Double.valueOf(mosaicQuantity);
int divisibility = mosaicFeeInformation.getDivisibility();
Double mosaicQuantityAddDivisibility = Double.valueOf(mosaicQuantityDouble.doubleValue() * Math.pow(10, divisibility));
quantity = Quantity.fromValue(mosaicQuantityAddDivisibility.longValue());
}
// get multisig publick key
String multisigPublicKey = KeyConvertor.getPublicKeyFromAddress(params.get("multisigAddress"));
if(StringUtils.isEmpty(multisigPublicKey)){
OutputMessage.error("unable to find multisig public key from multisig address");
return;
}
// send transaction
String cosignatoryPublicKey = params.get("cosignatoryPublicKey");
String cosignatoryPrivateKey = params.get("cosignatoryPrivateKey");
long amount = Long.valueOf(params.get("amount")).longValue();
String recipient = params.get("recipient");
String message = params.containsKey("message")?params.get("message"):"";
String fee = params.get("fee");
InitMultisigTransaction tx = new InitMultisigTransaction(cosignatoryPublicKey, cosignatoryPrivateKey, multisigPublicKey);
JSONObject result = JSONObject.fromObject(tx.send_v2(recipient, amount, message, mosaicId, quantity, fee));
if(result.containsKey("message") && "SUCCESS".equals(result.getString("message"))){
String transactionHash = result.getJSONObject("transactionHash").getString("data");
String innerTransactionHash = result.getJSONObject("innerTransactionHash").getString("data");
OutputMessage.initMultisigTransactionMessage("success", transactionHash, innerTransactionHash);
} else {
OutputMessage.error(result.getString("message"));
}
}
示例15: decodeJson
import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
* 將字符串轉換成HttpPacket
*
* @param stringResult
* 字符串
* @param isServer
* 是不是服務器一般傳true
* @param httpPacket
* 消息包
* @return
*/
public static boolean decodeJson(String stringResult, boolean isServer, HttpPacket httpPacket) {
try {
// 轉換成json獲取hOpCode,如果沒有看看頭消息有沒有
JSONObject jsObj = JSONObject.fromObject(stringResult);
String hOpCode;
if (jsObj.containsKey(AllowParam.HOPCODE)) {
hOpCode = jsObj.getString(AllowParam.HOPCODE);
} else if (httpPacket.hSession.headParam.hOpCode != null && !httpPacket.hSession.headParam.hOpCode.equals("")) {
hOpCode = httpPacket.hSession.headParam.hOpCode;
} else {
return false;
}
// 是否設定相應解析
if (!HttpManager.hOpCodeMap.containsKey(hOpCode)) {
if (HttpConfig.log != null) {
HttpConfig.log.warn("hOpCode為:" + hOpCode + "無對應解析,請及時解決");
}
return false;
}
// 解析
Class<?>[] classNames = HttpManager.hOpCodeMap.get(hOpCode);
Class<?> className;
if (isServer) {
className = classNames[0];
} else {
className = classNames[1];
}
Method buildM = className.getDeclaredMethod("newBuilder");
AbstractMessage.Builder<?> builder = (Builder<?>) buildM.invoke(null);
Message data = PacketUtils.jsonToProtoBuf(stringResult, builder);
if (data == null) {
return false;
}
// 設置hOpCode和消息體
httpPacket.sethOpCode(hOpCode);
httpPacket.setData(data);
return true;
} catch (Exception e) {
if (HttpConfig.log != null) {
HttpConfig.log.error("json轉換成protobuf異常", e);
}
return false;
}
}