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


Java JSONObject.containsKey方法代碼示例

本文整理匯總了Java中com.alibaba.fastjson.JSONObject.containsKey方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.containsKey方法的具體用法?Java JSONObject.containsKey怎麽用?Java JSONObject.containsKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.alibaba.fastjson.JSONObject的用法示例。


在下文中一共展示了JSONObject.containsKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getGroup

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@ApiOperation("獲取小組的信息")
@GetMapping("/{gid}")
public ResponseEntity getGroup(@PathVariable("gid") int gid,
                               @RequestParam(name = "isDetail", defaultValue = "false", required = false) boolean isDetail) {
    GroupEntity groupEntity = groupService.getGroup(gid);
    haveGroup(groupEntity);
    UserEntity userEntity = userService.getUserByUid(groupEntity.getOwner());
    String json = JSON.toJSONString(groupEntity);
    JSONObject jsonObject = JSON.parseObject(json);
    jsonObject.put("nickname", userEntity.getNickname());

    if (isDetail && SecurityUtils.getSubject().isAuthenticated()) {
        int uid = SessionHelper.get().getUid();
        if (uid != userEntity.getUid()) {
            throw new UnauthorizedException();
        }
    } else {
        // 對非本人創建小組屏蔽password
        if (jsonObject.containsKey("password")) {
            jsonObject.replace("password", "You can't see it!");
        }
    }
    return new ResponseEntity(jsonObject);
}
 
開發者ID:Eagle-OJ,項目名稱:eagle-oj-api,代碼行數:25,代碼來源:GroupController.java

示例2: getLong

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static Long getLong(String json, String key,
                       Long defaultVal) {
    JSONObject jsonObject = JSONObject.parseObject(json);
    try {
        if (jsonObject == null) {
            return defaultVal;
        }
        if (jsonObject.containsKey(key)) {
            return jsonObject.getLong(key);
        } else {
            return defaultVal;
        }
    } catch (Exception e) {
        return defaultVal;
    }
}
 
開發者ID:1991wangliang,項目名稱:lorne_core,代碼行數:17,代碼來源:JsonUtils.java

示例3: getAccessToken

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static AccessToken getAccessToken(String appId, String appSecret) {
	AccessToken token = null;
	String tockenUrl = WxApi.getTokenUrl(appId, appSecret);
	JSONObject jsonObject = httpsRequest(tockenUrl, HttpMethod.GET, null);
	if (null != jsonObject && !jsonObject.containsKey("errcode")) {
		try {
			token = new AccessToken();
			token.setAccessToken(jsonObject.getString("access_token"));
			token.setExpiresIn(jsonObject.getInteger("expires_in"));
		} catch (JSONException e) {
			token = null;//獲取token失敗
		}
	}else if(null != jsonObject){
		token = new AccessToken();
		token.setErrcode(jsonObject.getInteger("errcode"));
	}
	return token;
}
 
開發者ID:jmdhappy,項目名稱:xxpay-master,代碼行數:19,代碼來源:WxApi.java

示例4: initToken

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private static void initToken() {
	if (tokenTime == null || tokenExpire == null || System.currentTimeMillis() - tokenTime >= tokenExpire) {
		String uriString = "https://api.weixin.qq.com/cgi-bin/token?grant_type=" + grantType + "&appid="
				+ PropertiesUtil.getString("WX_PUBLIC_APPID") + "&secret="
				+ PropertiesUtil.getString("WX_PUBLIC_SECRET");
		try {
			URL url = new URL(uriString);
			HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
			InputStreamReader inputStreamReader = new InputStreamReader(httpsURLConnection.getInputStream());
			int responseInt = inputStreamReader.read();
			StringBuffer stringBuffer = new StringBuffer();
			while (responseInt != -1) {
				stringBuffer.append((char) responseInt);
				responseInt = inputStreamReader.read();
			}
			String tokenString = stringBuffer.toString();
			JSONObject jsonObject = JSON.parseObject(tokenString);
			if (jsonObject.containsKey("access_token")) {
				tokenTime = System.currentTimeMillis();
				token = jsonObject.getString("access_token");
				tokenExpire = jsonObject.getLong("expires_in");
			} else {
				// TODO 驗證錯誤
				System.out.println(jsonObject.get("errcode"));
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:31,代碼來源:WeiXinUtils.java

示例5: getToken

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * 正常情況  {"access_token":"ACCESS_TOKEN","expires_in":7200} 錯誤情況  {"errcode":40013,"errmsg":"invalid
 * appid"}
 */
public String getToken() {
	String replaceURL = null;
	replaceURL = tokenUrl.replace("APPID", appId).replace("APPSECRET", appSecret);
	String request = HttpClientUtil.sendGet(replaceURL, null, null);
	JSONObject object = JSON.parseObject(request);
	if (object.containsKey("access_token")) {
		return object.getString("access_token");
	}
	return null;
}
 
開發者ID:CharleyXu,項目名稱:tulingchat,代碼行數:15,代碼來源:TokenUtil.java

示例6: parseUploadResult

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private void parseUploadResult(String result) {
	JSONObject jsonObject = JSONObject.parseObject(result);
	if (jsonObject.containsKey(PARAM_MEDIA_ID)) {
		this.mediaId = jsonObject.getString(PARAM_MEDIA_ID);
		this.createdTimestamp = jsonObject.getString(PARAM_CREATE_TIME);
	} else {
		this.mediaId = null;
		this.createdTimestamp = null;
	}
}
 
開發者ID:funtl,項目名稱:framework,代碼行數:11,代碼來源:MediaFile.java

示例7: initToken

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private static void initToken() {
	if (tokenTime == null || tokenExpire == null || System.currentTimeMillis() - tokenTime >= tokenExpire
			|| token == null) {
		String uriString = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
		StringBuffer sb = new StringBuffer();
		sb.append(uriString);
		sb.append("?corpid=").append(PropertiesUtil.getString("WX_QY_CORPID"));
		sb.append("&corpsecret=").append(PropertiesUtil.getString("WX_QY_CORPSECRET"));

		try {
			System.out.println(sb);
			URL url = new URL(sb.toString());
			HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
			InputStreamReader inputStreamReader = new InputStreamReader(httpsURLConnection.getInputStream());
			int responseInt = inputStreamReader.read();
			StringBuffer stringBuffer = new StringBuffer();
			while (responseInt != -1) {
				stringBuffer.append((char) responseInt);
				responseInt = inputStreamReader.read();
			}
			String tokenString = stringBuffer.toString();
			System.out.println(stringBuffer);
			JSONObject jsonObject = JSON.parseObject(tokenString);
			if (jsonObject.containsKey("access_token")) {
				tokenTime = System.currentTimeMillis();
				token = jsonObject.getString("access_token");
				tokenExpire = jsonObject.getLong("expires_in");
			} else {
				// TODO 驗證錯誤
				System.out.println(jsonObject.get("errcode"));
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:37,代碼來源:WeiXinCompanyUtils.java

示例8: getExtra

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private static Object getExtra(JSONObject jsonObject)
{
    Object result = null;
    if (jsonObject.containsKey(EXTRA_FIELD))
    {
        result = jsonObject.get(EXTRA_FIELD);
        if (result instanceof String && ("true".equals(result) || "false".equals(result)))
        {
            result = Boolean.parseBoolean(result.toString());
        }
    }
    return result;
}
 
開發者ID:gzxishan,項目名稱:OftenPorter,代碼行數:14,代碼來源:JResponse.java

示例9: deleteKfAccount

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * 刪除客服帳號
 *
 * @param keFu
 * @return
 */
public static boolean deleteKfAccount(KeFu keFu) {
    boolean isOk = false;
    String token = WeiXinUtils.getToken();
    if (token != null) {
        String urlString = "https://api.weixin.qq.com/customservice/kfaccount/del?access_token=" + token;
        try {
            URL url = new URL(urlString);
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
            String kfAccountString = JSONObject.toJSONString(keFu);
            httpsURLConnection.setRequestProperty("Content-length", String.valueOf(kfAccountString.length()));
            httpsURLConnection.setRequestProperty("Content-Type", "application/json");
            httpsURLConnection.setDoOutput(true);
            httpsURLConnection.setDoInput(true);
            DataOutputStream dataOutputStream = new DataOutputStream(httpsURLConnection.getOutputStream());
            dataOutputStream.write(kfAccountString.getBytes());
            dataOutputStream.flush();
            dataOutputStream.close();
            DataInputStream dataInputStream = new DataInputStream(httpsURLConnection.getInputStream());
            StringBuffer stringBuffer = new StringBuffer();
            int inputByte = dataInputStream.read();
            while (inputByte != -1) {
                stringBuffer.append((char) inputByte);
                inputByte = dataInputStream.read();
            }
            String kfString = stringBuffer.toString();
            JSONObject jsonObject = JSON.parseObject(kfString);
            if (jsonObject.containsKey("errcode")) {
                int errcode = jsonObject.getIntValue("errcode");
                if (errcode == 0) {
                    isOk = true;
                } else {
                    //TODO 添加客服賬號失敗
                    isOk = false;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return isOk;
}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:48,代碼來源:WeiXinKFUtils.java

示例10: getInt

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static int getInt(String json, String key, int defaultVal) {
    JSONObject jsonObject = JSONObject.parseObject(json);
    try {
        if (jsonObject == null) {
            return defaultVal;
        }
        if (jsonObject.containsKey(key)) {
            return jsonObject.getInteger(key);
        } else {
            return defaultVal;
        }
    } catch (Exception e) {
        return defaultVal;
    }
}
 
開發者ID:1991wangliang,項目名稱:lorne_core,代碼行數:16,代碼來源:JsonUtils.java

示例11: insertKfAccount

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
 * 添加客服帳號
 *
 * @param keFu
 * @return
 */
public static boolean insertKfAccount(KeFu keFu) {
    boolean isOk = false;
    String token = WeiXinUtils.getToken();
    if (token != null) {
        String urlString = "https://api.weixin.qq.com/customservice/kfaccount/add?access_token=" + token;
        try {
            URL url = new URL(urlString);
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
            String kfAccountString = JSONObject.toJSONString(keFu);
            httpsURLConnection.setRequestProperty("Content-length", String.valueOf(kfAccountString.length()));
            httpsURLConnection.setRequestProperty("Content-Type", "application/json");
            httpsURLConnection.setDoOutput(true);
            httpsURLConnection.setDoInput(true);
            DataOutputStream dataOutputStream = new DataOutputStream(httpsURLConnection.getOutputStream());
            dataOutputStream.write(kfAccountString.getBytes());
            dataOutputStream.flush();
            dataOutputStream.close();
            DataInputStream dataInputStream = new DataInputStream(httpsURLConnection.getInputStream());
            StringBuffer stringBuffer = new StringBuffer();
            int inputByte = dataInputStream.read();
            while (inputByte != -1) {
                stringBuffer.append((char) inputByte);
                inputByte = dataInputStream.read();
            }
            String kfString = stringBuffer.toString();
            JSONObject jsonObject = JSON.parseObject(kfString);
            if (jsonObject.containsKey("errcode")) {
                int errcode = jsonObject.getIntValue("errcode");
                if (errcode == 0) {
                    isOk = true;
                } else {
                    //TODO 添加客服賬號失敗
                    isOk = false;
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    return isOk;
}
 
開發者ID:tb544731152,項目名稱:iBase4J,代碼行數:48,代碼來源:WeiXinKFUtils.java

示例12: isCompactedArrayFormat

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private boolean isCompactedArrayFormat(JSONObject object) {
    return object.size() == 2
            && object.containsKey("_h")
            && object.containsKey("_d");
}
 
開發者ID:bingoohuang,項目名稱:westjson,代碼行數:6,代碼來源:WestJsonUncompacter.java

示例13: TestCreateAccount

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public static BubiKey TestCreateAccount(String url, String srcAddress, String srcPrivate, String srcPublic, String signerAddress,
		String signerPrivate, String signerPublic, int masterWeight, int threshold, BubiKeyType algorithm, CertFileType certFileType, String certFile, String password) {
	BubiKey bubikey_new = null;
	try {
		// get hash type
		String getHello = url + "/hello";
		String hello = HttpKit.post(getHello, "");
		JSONObject ho = JSONObject.parseObject(hello);
		Integer hash_type = ho.containsKey("hash_type") ? ho.getInteger("hash_type") : 0;
		
		// getAccount
		String getAccount = url + "/getAccount?address=" + srcAddress;
		String txSeq = HttpKit.post(getAccount, "");
		JSONObject tx = JSONObject.parseObject(txSeq);
		String seq_str = tx.getJSONObject("result").containsKey("nonce") ? tx.getJSONObject("result").getString("nonce") : "0";
		long nonce = Long.parseLong(seq_str);
		
		// generate new Account address, PrivateKey, publicKey
		if (algorithm == BubiKeyType.CFCA) {
			byte fileData[] = FileUtil.getBytesFromFile(certFile);
			bubikey_new = new BubiKey(certFileType, fileData, password);
		}
		else {
			bubikey_new = new BubiKey(algorithm);
		}
		String newAccountAddress = bubikey_new.getB16Address();
		
		// use src account sign
		BubiKey bubiKey_src = new BubiKey(srcPrivate, srcPublic);
		BubiKey bubiKey_sign = new BubiKey(signerPrivate, signerPublic);
		
		// generate transaction
		Transaction.Builder tran = Transaction.newBuilder();
		tran.setSourceAddress(srcAddress);
		tran.setNonce(nonce + 1);
		Operation.Builder oper = tran.addOperationsBuilder();
		oper.setType(Operation.Type.CREATE_ACCOUNT);
		OperationCreateAccount.Builder createAccount = OperationCreateAccount.newBuilder();
		AccountPrivilege.Builder accountPrivilege = AccountPrivilege.newBuilder();
		accountPrivilege.setMasterWeight(masterWeight);
		AccountThreshold.Builder accountThreshold = AccountThreshold.newBuilder();
		accountThreshold.setTxThreshold(threshold);
		accountPrivilege.setThresholds(accountThreshold);
		
		createAccount.setPriv(accountPrivilege);
		createAccount.setDestAddress(newAccountAddress);
		oper.setCreateAccount(createAccount);
		
		// generate hex string of transaction's hash
		String hash = HashUtil.GenerateHashHex(tran.build().toByteArray(), hash_type);
		System.out.println("hash: " + hash);
		
		// add transaction with signature
		JSONObject request = new JSONObject();
		JSONArray items = new JSONArray();
		JSONObject item = new JSONObject();
		item.put("transaction_blob", cn.bubi.baas.utils.encryption.utils.HexFormat.byteToHex(tran.build().toByteArray()));
		JSONArray signatures = new JSONArray();
		JSONObject signature = new JSONObject();
		signature.put("sign_data", cn.bubi.baas.utils.encryption.utils.HexFormat.byteToHex(bubiKey_sign.sign(tran.build().toByteArray())));
		signature.put("public_key", signerPublic);
		signatures.add(signature);
		item.put("signatures", signatures);
		items.add(item);
		request.put("items", items);
		System.out.println("src sign_data: " + cn.bubi.baas.utils.encryption.utils.HexFormat.byteToHex(bubiKey_src.sign(tran.build().toByteArray())));
		System.out.println("src public key: " + bubiKey_src.getB16PublicKey());
		System.out.println("Transaction: " + tran);
		System.out.println("Signatures: " + signatures);
		
		String submitTransaction = url + "/submitTransaction";
		String result = HttpKit.post(submitTransaction, request.toJSONString());
		System.out.println(result);
		
	} catch (Exception e) {
		e.printStackTrace();
	}
	
	return bubikey_new;
}
 
開發者ID:bubicn,項目名稱:bubichain-sdk-java,代碼行數:81,代碼來源:TestBubikey.java

示例14: pushNative

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@JSMethod
public void pushNative(String encodeParam, JSCallback callback) {
    if (TextUtils.isEmpty(encodeParam)) {
        return;
    }
    try {
        JSONObject options = JSON.parseObject(encodeParam);
        String url = "";
        UWXTheme.NavBar navBar = null;
        JSONObject param = null;
        if (options.containsKey(UWXBundleInfo.KEY_URL)) {
            url = options.getString(UWXBundleInfo.KEY_URL);
        }
        if (options.containsKey(UWXBundleInfo.KEY_NAV_BAR)) {
            String _navBar = options.getString(UWXBundleInfo.KEY_NAV_BAR);
            if (!TextUtils.isEmpty(_navBar)) {
                navBar = JSON.parseObject(_navBar, UWXTheme.NavBar.class);
            }
        }
        if (options.containsKey(UWXBundleInfo.KEY_PARAM)) {
            param = options.getJSONObject(UWXBundleInfo.KEY_PARAM);
        }
        UWLog.v("params=" + encodeParam);
        if (!TextUtils.isEmpty(url)) {
            UWXNavigatorAdapter navigatorAdapter = UWXSDKManager.getInstance().getNavigatorAdapter();
            if (navigatorAdapter != null) {
                navigatorAdapter.pushNative((Activity) mWXSDKInstance.getContext(),url ,param);
                if (callback != null) {
                    callback.invoke(MSG_SUCCESS);
                }
            }
        } else {
            callback.invoke(MSG_FAILED);
        }
    } catch (Exception e) {
        WXLogUtils.eTag(TAG, e);
        if (callback != null) {
            callback.invoke(MSG_FAILED);
        }
    }
}
 
開發者ID:weexext,項目名稱:ucar-weex-core,代碼行數:42,代碼來源:UWXNavigatorModule.java

示例15: load

import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
private void load(JSONObject data) {
    path = data.getString(KEY_PATH);
    md5 = data.getString(KEY_MD5);
    url = data.getString(KEY_URL);
    size = data.containsKey(KEY_SIZE) ? data.getLong(KEY_SIZE) : 0;
}
 
開發者ID:newDeepLearing,項目名稱:decoy,代碼行數:7,代碼來源:SnapChatAttachment.java


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