本文整理汇总了Java中net.sf.json.JSONArray.size方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.size方法的具体用法?Java JSONArray.size怎么用?Java JSONArray.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateMosaic
import net.sf.json.JSONArray; //导入方法依赖的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: handleJson
import net.sf.json.JSONArray; //导入方法依赖的package包/类
public void handleJson(String jsonContent) throws Exception {
JSONArray array = JSONArray.fromObject(jsonContent);
JSONObject object = null;
int l = array.size();
for (int i = 0; i < l; i++) {
object = array.getJSONObject(i);
JSONObject obj1 = (JSONObject) object.get("data");
JSONObject obj2 = (JSONObject) obj1.get("archives");
for (int j = 0; j < 20; j++) {
JSONObject obj3 = (JSONObject) obj2.get(String.valueOf(j));
Bilibili video = new Bilibili();
video.setAid(Integer.parseInt(obj3.get("aid").toString()));
video.setTid(Integer.parseInt(obj3.get("tid").toString()));
video.setTname((obj3.get("tname")).toString());
video.setTitle((obj3.get("title")).toString());
video.setAuthor((obj3.get("author")).toString());
JSONObject obj4 = (JSONObject) obj3.get("stat");
video.setCoin(Integer.parseInt(obj4.get("coin").toString()));
video.setFavorite(Integer.parseInt(obj4.get("favorite").toString()));
JDBC.insertBilibiliData(conn, video);
}
}
}
示例3: getDiscussUsers
import net.sf.json.JSONArray; //导入方法依赖的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;
}
示例4: getDiscussList
import net.sf.json.JSONArray; //导入方法依赖的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;
}
示例5: getGroupList
import net.sf.json.JSONArray; //导入方法依赖的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;
}
示例6: getDTOArray
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* 从一个JSON数组得到一个java对象数组,形如: [{"id" : idValue, "name" : nameValue}, {"id" :
* idValue, "name" : nameValue}, ...]
*
* @param object
* @param clazz
* @return
*/
public static Object[] getDTOArray(String jsonString, Class<?> clazz) {
setDataFormat2JAVA();
JSONArray array = JSONArray.fromObject(jsonString);
Object[] obj = new Object[array.size()];
for (int i = 0; i < array.size(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
obj[i] = JSONObject.toBean(jsonObject, clazz);
}
return obj;
}
示例7: getVideoNumber
import net.sf.json.JSONArray; //导入方法依赖的package包/类
public int getVideoNumber(String jsonContent) throws Exception {
JSONArray array = JSONArray.fromObject(jsonContent);
JSONObject object = null;
int l = array.size();
int videoNumber = 0;
for (int i = 0; i < l; i++) {
object = array.getJSONObject(i);
JSONObject obj1 = (JSONObject) object.get("data");
JSONObject obj2 = (JSONObject) obj1.get("page");
videoNumber = Integer.parseInt(obj2.get("count").toString());
}
return videoNumber;
}
示例8: getFriendList
import net.sf.json.JSONArray; //导入方法依赖的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;
}
示例9: findMosaicFeeInformationByNIS
import net.sf.json.JSONArray; //导入方法依赖的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;
}
示例10: getCategories
import net.sf.json.JSONArray; //导入方法依赖的package包/类
public ArrayList<String> getCategories(){
ArrayList<String> categories=new ArrayList<String>();
JSONObject r=new JSONObject();
//构造一个请求表单
r.put("vfwebqq",credential.getVfWebQQ());
//这里用到了hash
r.put("hash", credential.getHash());
//访问获取好友列表的链接,取出分组信息
JSONArray result=JSONObject.fromObject(JSONObject.fromObject(utils.post(URL.URL_GET_FRIEND_LIST,new PostParameter[]{new PostParameter("r",r.toString())},new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result")).getJSONArray("categories");
//取出分组的名称
for(int i=0;i<result.size();i++){
categories.add(JSONObject.fromObject(result.get(i)).getString("name"));
}
return categories;
}
示例11: findMosaicFeeInformationByNIS
import net.sf.json.JSONArray; //导入方法依赖的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;
}
示例12: chatRecord
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* 聊天记录,跟某个人之间,一个会话的聊天记录,两个人之间的聊天记录
* @param id 跟自己会话的那个人的id,对方的id
*/
@RequestMapping("chatRecord")
public String chatRecord(HttpServletRequest request,Model model,
@RequestParam(value = "id", required = false , defaultValue="0") long id){
if(id == 0){
return error(model, "请输入要查看得对方得id编号");
}
User user = getUser();
int currentTime = DateUtil.timeForUnix10();
int startTime = currentTime - 86400*30; //30天内有效
try {
AliyunLogPageUtil log = new AliyunLogPageUtil(Global.aliyunLogUtil);
JSONArray jsonArray = log.listForJSONArray("(receiveId = "+user.getId()+" and sendId = "+id+" ) or (receiveId = "+id+" and sendId = "+user.getId()+" )", "", false, startTime, currentTime, 100, request);
JSONArray ja = new JSONArray(); //将其倒序
for (int i = jsonArray.size()-1; i >-1 ; --i) {
ja.add(jsonArray.get(i));
}
model.addAttribute("list", ja);
} catch (LogException e) {
e.printStackTrace();
}
model.addAttribute("user", user);
return "im/chatRecord";
}
示例13: initGlobalDataConfig
import net.sf.json.JSONArray; //导入方法依赖的package包/类
protected void initGlobalDataConfig(JSON globalDataConfigs) {
JSONArray array = getGlobalConfigsArray(globalDataConfigs);
for (int i = 0; i < array.size(); i++) {
JSONObject jsonobject = array.getJSONObject(i);
addGlobalConfigDataForSonarInstance(jsonobject);
}
}
示例14: parseString
import net.sf.json.JSONArray; //导入方法依赖的package包/类
@Override
protected String parseString(String jsonString) {
JSONArray jsonArray = JSONArray.fromObject(jsonString);
JSONArray segments = jsonArray.getJSONArray(0);
StringBuilder result = new StringBuilder();
for (int i = 0; i < segments.size(); i++) {
result.append(segments.getJSONArray(i).getString(0));
result.append("\r\n");
}
return new String(result);
}
示例15: monitorCosignUnconfirmed
import net.sf.json.JSONArray; //导入方法依赖的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());
}