本文整理匯總了Java中net.sf.json.JSONObject.getJSONArray方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.getJSONArray方法的具體用法?Java JSONObject.getJSONArray怎麽用?Java JSONObject.getJSONArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.sf.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.getJSONArray方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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";
}
示例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;
}
示例3: 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;
}
示例4: 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;
}
示例5: getFriendList
import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
* 獲取好友列表相當於組裏的所有人
*
* @param userGroupTopId
* 組id
* @param token
* 身份
* @return
*/
public static List<UserData> getFriendList(String userGroupTopId, String token) {
JSONObject js = new JSONObject();
js.put("hOpCode", "13");
js.put("userGroupTopId", userGroupTopId);
Map<String, String> header = new HashMap<>();
header.put("hOpCode", "13");
header.put("token", token);
byte[] returnByte = HttpUtil.send(js.toString(), CommonConfigChat.IDENTITY_URL, header, HttpUtil.POST);
if (returnByte != null) {
String str = null;
try {
str = new String(returnByte, "UTF-8");
} catch (UnsupportedEncodingException e) {
WSManager.log.error("返回字符串解析異常", e);
}
JSONObject returnjs = JSONObject.fromObject(str);
// 如果返回的是錯誤類型,說明用戶中心攔截器沒通過
if (returnjs.getString("hOpCode").equals("0")) {
return null;
}
JSONArray jsArray = returnjs.getJSONArray("user");
List<UserData> list = new ArrayList<>();
for (int i = 0; i < jsArray.size(); i++) {
JSONObject user = jsArray.getJSONObject(i);
UserData userData = new UserData(user);
list.add(userData);
}
return list;
}
return null;
}
示例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: 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;
}
示例8: 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());
}
示例9: 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;
}