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


Java JSONObject.getLong方法代碼示例

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


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

示例1: validateMosaic

import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
 * validate the mosaic and quantity
 * @param address
 * @param mosaicName
 * @param mosaicQuantity
 * @param mosaicFeeInformation
 * @return
 */
private static String validateMosaic(String address, String mosaicName, String mosaicQuantity, MosaicFeeInformation mosaicFeeInformation) {
	String queryResult = HttpClientUtils.get(Constants.URL_ACCOUNT_MOSAIC_OWNED + "?address=" + address);
	JSONObject json = JSONObject.fromObject(queryResult);
	JSONArray array = json.getJSONArray("data");
	for(int i=0;i<array.size();i++){
		JSONObject item = array.getJSONObject(i);
		// get mosaic id
		JSONObject mosaicId = item.getJSONObject("mosaicId");
		String namespaceId = mosaicId.getString("namespaceId");
		String name = mosaicId.getString("name");
		// get mosaic quantity
		long quantity = item.getLong("quantity");
		if(mosaicName.equals(namespaceId+":"+name)){
			Double mQuantity = Double.valueOf(mosaicQuantity).doubleValue() * Math.pow(10, mosaicFeeInformation.getDivisibility());
			if(mQuantity.longValue()>quantity){
				return "insufficient mosaic quantity";
			} else {
				return null;
			}
		}
	}
	return "there is no mosaic ["+mosaicName+"] in the account";
}
 
開發者ID:NEMChina,項目名稱:nem-apps,代碼行數:32,代碼來源:ImplInitMultisigTransaction.java

示例2: getDiscussUsers

import net.sf.json.JSONObject; //導入方法依賴的package包/類
public ArrayList<User> getDiscussUsers(){
	ArrayList<User> users=new ArrayList<User>();
	//用這個討論組的did,以及vfwebqq合成一個完整的URL,並且將結果解析為json對象
	String url=URL.URL_GET_DISCUSS_INFO.replace("[var]",Long.toString(discussID)).replace("[var1]",credential.getVfWebQQ()).replace("[var2]",credential.getPsessionID());
	String info=utils.get(url,new HttpHeader[]{URL.URL_MESSAGE_REFERER,credential.getCookie()}).getContent("UTF-8");
	JSONObject result=JSONObject.fromObject(info).getJSONObject("result");
	//獲取用戶信息
	JSONArray usersInfo=result.getJSONArray("mem_info");
	//獲取在線狀態
	JSONArray usersStatus=result.getJSONArray("mem_status");
	//設置昵稱,狀態以及uin
	int tempIndex=0;
	for(int i=0;i<usersInfo.size();i++){
		JSONObject tempUserInfo=JSONObject.fromObject(usersInfo.get(i));
		User tempUser=new User(tempUserInfo.getLong("uin"));
		tempUser.setNickName(tempUserInfo.getString("nick"));
		if(tempIndex<usersStatus.size()&&tempUser.getUID()==JSONObject.fromObject(usersStatus.get(tempIndex)).getLong("uin")){
			tempUser.setOnlineStatus(true);
			tempIndex++;
	}
		users.add(tempUser);
	}
	return users;
	
}
 
開發者ID:KittenDev,項目名稱:WebQQAPI,代碼行數:26,代碼來源:Discuss.java

示例3: getSelfInfo

import net.sf.json.JSONObject; //導入方法依賴的package包/類
public final User getSelfInfo(){
	JSONObject data=JSONObject.fromObject(utils.get(URL.URL_GET_SELF_INFO,new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8"));
	JSONObject info=data.getJSONObject("result");
	//獲取生日
	JSONObject birthday=info.getJSONObject("birthday");
	//構造一個用戶
	User user=new User(info.getLong("account"));
	//設置昵稱為結果內的nick值
	user.setNickName(info.getString("nick"));
	//設置性別為結果內的gender值,有male,female,unknown三種屬性
	user.setGender(info.getString("gender"));
	//設置生日
	user.setBirthday(birthday.getInt("year")+"-"+birthday.getInt("month")+"-"+birthday.getInt("day"));
	//設置vip級別
	user.setVipLevel(info.getInt("vip_info"));
	//獲取自己的簽名
	user.setPersonal(info.getString("lnick"));
	//設置自己的頭像
	user.setLogo(logoUtil.getUserLogoByUin(info.getLong("account")));
	return user;
}
 
開發者ID:KittenDev,項目名稱:WebQQAPI,代碼行數:22,代碼來源:Account.java

示例4: getDiscussList

import net.sf.json.JSONObject; //導入方法依賴的package包/類
public ArrayList<Discuss> getDiscussList(){
	ArrayList<Discuss> discussesList=new ArrayList<Discuss>();
	//用psessionid合成一個完整的URL並且訪問它,並將結果解析為json
	JSONObject result=JSONObject.fromObject(utils.get(URL.URL_GET_DISCUSS_LIST.replace("[var]",credential.getPsessionID()).replace("[var1]",credential.getVfWebQQ()),new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result");
	//獲取討論組列表
	JSONArray discussesListInfo=result.getJSONArray("dnamelist");
	//構造討論組列表
	for(int i=0;i<discussesListInfo.size();i++){
		JSONObject tempDiscussInfo=JSONObject.fromObject(discussesListInfo.get(i));
		//取出討論組id,構造一個討論組,credential用於獲取成員列表
		Discuss tempDiscuss=new Discuss(tempDiscussInfo.getLong("did"),credential);
		//設置討論組的名稱
		tempDiscuss.setName(tempDiscussInfo.getString("name"));
		//添加到list內
		discussesList.add(tempDiscuss);
	}
	return discussesList;
}
 
開發者ID:KittenDev,項目名稱:WebQQAPI,代碼行數:19,代碼來源:Account.java

示例5: getGroupList

import net.sf.json.JSONObject; //導入方法依賴的package包/類
public ArrayList<Group> getGroupList(){
	ArrayList<Group> groupsList=new ArrayList<Group>();
	JSONObject r=new JSONObject();
	r.put("vfwebqq",credential.getVfWebQQ());
	r.put("hash",credential.getHash());
	//構造一個請求表單,用於獲取群列表
	
	//訪問獲取群信息的鏈接,並將結果解析為json
	JSONObject result=JSONObject.fromObject(utils.post(URL.URL_GET_GROUP_LIST,new PostParameter[]{new PostParameter("r",r.toString())},new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result");
	//從結果取出群列表
	JSONArray groups=result.getJSONArray("gnamelist");
	//構造群對象
	for(int i=0;i<groups.size();i++){
		JSONObject tempInfo=JSONObject.fromObject(groups.get(i));
		//構造一個群對象,gid為群id,gcode用於獲取成員,credential用於獲取成員列表
		Group tempGroup=new Group(tempInfo.getLong("gid"),tempInfo.getLong("code"),credential);
		//設置群的名稱
		tempGroup.setName(tempInfo.getString("name"));
		groupsList.add(tempGroup);
	}
	return groupsList;
}
 
開發者ID:KittenDev,項目名稱:WebQQAPI,代碼行數:23,代碼來源:Account.java

示例6: getCredential

import net.sf.json.JSONObject; //導入方法依賴的package包/類
public static Credential getCredential(String url,HttpHeader cookies){
	HttpUtils util=new HttpUtils();
	//必須設置不跟隨重定向,否則無法取得cookies
	util.setGetFollowRedirect(false);
	//訪問302跳轉的url
	Response response=util.get(url);
	StringBuffer cookie=new StringBuffer();
	//取出cookies
	ArrayList<HttpHeader> headers=response.getHeaders();
	String[] cookieArray=cookies.getValue().split(" ");
	String ptwebqq=null;
	for(int i=0;i<cookieArray.length;i++){
		//獲取ptwebqq
		if(cookieArray[i].contains("ptwebqq")){
			ptwebqq=cookieArray[i].substring(cookieArray[i].indexOf("=")+1,cookieArray[i].indexOf(";"));
			break;
		}
	}
	//在cookies內添加ptwebqq項
	cookie.append("ptwebqq="+ptwebqq+"; ");
	for(int i=0;i<headers.size();i++){
		if(headers.get(i).getHeader()==null){
			continue;
		}
		if(headers.get(i).getHeader().equals("Set-Cookie")){
		String temp=headers.get(i).getValue().substring(0,headers.get(i).getValue().indexOf(";")+1);
		//判斷每一項cookie的值是否為空,如果等於號後麵直接就是分號結尾,那就是空值,需要過濾
		if(!temp.substring(temp.indexOf("=")+1,temp.length()).equals(";")){
		cookie.append(temp+" ");
		}
		}
	}
	//生成一個登錄表單
	JSONObject r=new JSONObject();
	r.put("ptwebqq",ptwebqq);
	r.put("clientid",53999199);
	r.put("psessionid","");
	r.put("status","online");
	//訪問登錄鏈接,需要帶上前麵的cookies訪問
	Response loginResult=util.post(URL.URL_LOGIN,new PostParameter[]{new PostParameter("r",r.toString())},new HttpHeader[]{new HttpHeader("Cookie",cookie.toString())});
	JSONObject result=JSONObject.fromObject(JSONObject.fromObject(loginResult.getContent("UTF-8")));
	JSONObject data=JSONObject.fromObject(result.get("result"));
	//獲取自己的uin
	long uin=data.getLong("uin");
	//獲取psessionid,這個在收發消息需要用到
	String psessionid=data.getString("psessionid");
	//獲取vfwebqq,必須帶上Referer和前麵的cookies
	String vfwebqq_temp=util.get(URL.URL_GET_VFWEBQQ,new HttpHeader[]{URL.URL_REFERER,new HttpHeader("Cookie",cookie.toString())}).getContent("UTF-8");
	//將結果解析為JSON對象
	JSONObject result_jsonObj=JSONObject.fromObject(vfwebqq_temp);
	//構造一個憑據對象,將獲取到的數據全部傳入
	Credential credential=new Credential(uin,result_jsonObj.getJSONObject("result").getString("vfwebqq"),psessionid,ptwebqq,new HttpHeader("Cookie",cookie.toString()));
	//返回碼,這個可有可無,無所謂
	credential.setRetcode(result.getInt("retcode"));
	return credential;
}
 
開發者ID:KittenDev,項目名稱:WebQQAPI,代碼行數:57,代碼來源:QrcodeLogin.java

示例7: 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());
}
 
開發者ID:NEMChina,項目名稱:nem-apps,代碼行數:54,代碼來源:WsMonitorMultisigHandler.java

示例8: getGroupUsers

import net.sf.json.JSONObject; //導入方法依賴的package包/類
public ArrayList<User> getGroupUsers(){
	ArrayList<User> users=new ArrayList<User>();
	//用群id,vfwebqq合成一個完整的URL並且帶上cookies和referer訪問,將結果解析為json對象
	JSONObject result=JSONObject.fromObject(utils.get(URL.URL_GET_GROUP_INFO.replace("[var]",Long.toString(gcode)).replace("[var1]",credential.getVfWebQQ()),new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result");
	//獲取成員列表
	JSONArray members=result.getJSONArray("minfo");
	//獲取群名片
	JSONArray cards=new JSONArray();
	//如果沒有人設置群名片則此處會引發異常
	try{
	cards=result.getJSONArray("cards");
	}catch(JSONException e){
		
	}
	//獲取群成員的vip信息
	JSONArray vip_info=result.getJSONArray("vipinfo");
	//遍曆成員列表,填充到成員list內
	int tempIndex=0;
	for(int i=0;i<members.size();i++){
		JSONObject tempMemberInfo=JSONObject.fromObject(members.get(i));
		User tempUser=new User(tempMemberInfo.getLong("uin"));
		tempUser.setNickName(tempMemberInfo.getString("nick"));
		tempUser.setGender(tempMemberInfo.getString("gender"));
		tempUser.setVipLevel(JSONObject.fromObject(vip_info.get(i)).getInt("vip_level"));
		if(tempIndex<cards.size()&&JSONObject.fromObject(cards.get(tempIndex)).getLong("muin")==tempUser.getUID()){
		tempUser.setMarkName(JSONObject.fromObject(cards.get(tempIndex)).getString("card"));
		tempIndex++;
		}
		users.add(tempUser);
	}
	return users;
	
}
 
開發者ID:KittenDev,項目名稱:WebQQAPI,代碼行數:34,代碼來源:Group.java


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