当前位置: 首页>>代码示例>>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;未经允许,请勿转载。