当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.size方法代码示例

本文整理汇总了Java中com.alibaba.fastjson.JSONArray.size方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.size方法的具体用法?Java JSONArray.size怎么用?Java JSONArray.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.alibaba.fastjson.JSONArray的用法示例。


在下文中一共展示了JSONArray.size方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: main

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
@Test
public void main() throws IOException {
    File a = FileUtils.getFile("D:/a.txt");
    String str = FileUtils.readFileToString(a,"utf-8");
    JSONObject json = JSON.parseObject(str);
    JSONArray arry = JSONArray.parseArray(json.get("delegates").toString());
    for(int i = 0;i<arry.size();i++){
        JSONObject obj= (JSONObject) arry.get(i);
        String username =  obj.getString("username");
        String productivity =  obj.getString("productivity");
        String producedblocks = obj.getString("producedblocks");
        String balance = obj.getString("balance");
        String approval = obj.getString("approval");
        System.out.println(username +"||" + productivity +"||" + producedblocks + "||" + balance + "||" + approval);
    }
}
 
开发者ID:AschPlatform,项目名称:asch-java,代码行数:17,代码来源:AccountServiceTest.java

示例2: test_scanInt

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void test_scanInt() throws Exception {
    StringBuffer buf = new StringBuffer();
    buf.append('[');
    for (int i = 0; i < 1024; ++i) {
        if (i != 0) {
            buf.append(',');
        }
        buf.append(i + ".0");
    }
    buf.append(']');

    Reader reader = new StringReader(buf.toString());

    JSONReaderScanner scanner = new JSONReaderScanner(reader);

    DefaultJSONParser parser = new DefaultJSONParser(scanner);
    JSONArray array = (JSONArray) parser.parse();
    for (int i = 0; i < array.size(); ++i) {
        BigDecimal value = new BigDecimal(i + ".0");
        Assert.assertEquals(value, array.get(i));
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:JSONReaderScannerTest_decimal.java

示例3: rolePermission

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
@Override
public int rolePermission(JSONArray datas, int id) {
    List<Integer> deleteIds = new ArrayList<>();
    for (int i = 0; i < datas.size(); i ++) {
        JSONObject json = datas.getJSONObject(i);
        if (!json.getBoolean("checked")) {
            deleteIds.add(json.getIntValue("id"));
        } else {
            // 新增权限
            UpmsRolePermission upmsRolePermission = new UpmsRolePermission();
            upmsRolePermission.setRoleId(id);
            upmsRolePermission.setPermissionId(json.getIntValue("id"));
            upmsRolePermissionMapper.insertSelective(upmsRolePermission);
        }
    }
    // 删除权限
    if (deleteIds.size() > 0) {
        UpmsRolePermissionExample upmsRolePermissionExample = new UpmsRolePermissionExample();
        upmsRolePermissionExample.createCriteria()
                .andPermissionIdIn(deleteIds)
                .andRoleIdEqualTo(id);
        upmsRolePermissionMapper.deleteByExample(upmsRolePermissionExample);
    }
    return datas.size();
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:26,代码来源:UpmsRolePermissionServiceImpl.java

示例4: containsJsonValue

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
/**
 * 在json对象里是否含有指定的键值
 *
 * @param array  存放的是json对象
 * @param key
 * @param object
 * @return 存在则,返回对应索引;不存在返回-1.
 */
public static int containsJsonValue(JSONArray array, String key, Object object)
{
    int index = -1;

    for (int i = 0; i < array.size(); i++)
    {
        JSONObject jsonObject = array.getJSONObject(i);
        if (jsonObject.containsKey(key) && jsonObject.get(key).equals(object))
        {
            index = i;
            break;
        }
    }

    return index;
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:25,代码来源:WPTool.java

示例5: deserialze

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> T deserialze(DefaultJSONParser parser, Type clazz, Object fieldName) {
    if (parser.getLexer().token() == JSONToken.NULL) {
        parser.getLexer().nextToken(JSONToken.COMMA);
        return null;
    }

    JSONArray array = new JSONArray();
    parser.parseArray(array);

    AtomicIntegerArray atomicArray = new AtomicIntegerArray(array.size());
    for (int i = 0; i < array.size(); ++i) {
        atomicArray.set(i, array.getInteger(i));
    }

    return (T) atomicArray;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:18,代码来源:AtomicIntegerArrayCodec.java

示例6: getProcessOrders

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
private List<ProcessOrder> getProcessOrders(ProcessPo processPo) {
    JSONArray jsonArray = JSON.parseArray(processPo.getProcessOrder());
    List<ProcessOrder> processOrders = new ArrayList<>();
    for (int i = 0; i < jsonArray.size(); i++) {
        ProcessOrder processOrder = new ProcessOrder();
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        processOrder.setProcessOrder(jsonObject.getInteger("processOrder"));
        try {
            processOrder.setProcessClass(Class.forName(jsonObject.getString("processClazz")));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
        processOrders.add(processOrder);
    }
    return processOrders;
}
 
开发者ID:Yanweichen,项目名称:SimpleProcessControl,代码行数:17,代码来源:ProcessCRUDService.java

示例7: read

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public static NatureAttribute read(DataInput in) {
    try {
        NatureAttribute attribute = new NatureAttribute();
        attribute.totalFrequency = in.readInt();
        String json = in.readUTF();
        JSONArray array = JSON.parseArray(json);

        ImmutableMap.Builder<Nature, Integer> builder = ImmutableMap.builder();
        for (int i = 0; i < array.size(); i += 2) {
            int ord = array.getIntValue(i);
            Integer freq = array.getInteger(i + 1);

            builder.put(Nature.valueOf(ord), freq);
        }

        attribute.map = builder.build();

        return attribute;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

}
 
开发者ID:mayabot,项目名称:mynlp,代码行数:24,代码来源:NatureAttribute.java

示例8: convert

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
@Override
public ArrayList<MultipleItemEntity> convert() {
    final JSONArray array = JSON.parseObject(getJsonData()).getJSONArray("data");
    final int size = array.size();
    for (int i = 0; i < size; i++) {
        final JSONObject data = array.getJSONObject(i);
        final String thumb = data.getString("thumb");
        final String title = data.getString("title");
        final int id = data.getInteger("id");
        final double price = data.getDouble("price");
        final String time = data.getString("time");

        final MultipleItemEntity entity = MultipleItemEntity.builder()
                .setItemType(OrderListItemType.ITEM_ORDER_LIST)
                .setField(MultipleFields.ID, id)
                .setField(MultipleFields.IMAGE_URL, thumb)
                .setField(MultipleFields.TITLE, title)
                .setField(OrderItemFields.PRICE, price)
                .setField(OrderItemFields.TIME, time)
                .build();
        ENTITIES.add(entity);

    }

    return ENTITIES;
}
 
开发者ID:remerber,项目名称:FastEc,代码行数:27,代码来源:OrderListDataConverter.java

示例9: getResponse

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
@Override
public Object getResponse(ServiceRequest request, InputStream responseStream, HttpServiceContext serviceContext) throws Exception{
    String jsonResponse = (String) StringResponseConverter.INSTANCE.getResponse(request, responseStream, null);
    if (jsonResponse == null) {
        return null;
    }
    jsonResponse = jsonResponse.trim();

    JSONObject responseJSON = JSONObject.parseObject(jsonResponse);
    JSONArray results = responseJSON.getJSONArray("results");
    if (results.size() == 0) {
        throw new BlockchainException("Submit transaction fail! --Response empty results!");
    }

    JSONObject result = results.getJSONObject(0);
    if (responseJSON.getInteger("success_count") == 0) {
        logger.info(result.toJSONString());
        int errorCode = result.getInteger("error_code");
        String errorDesc = result.getString("error_desc");
        if (StringUtils.isEmpty(errorDesc)) {
            errorDesc = BlockchainError.getDescription(errorCode);
        }
        throw new BlockchainException(errorCode, " sync submit transaction fail! --[ErrorCode=" + errorCode + "] --" + errorDesc);
    }

    return result.getString("hash");
}
 
开发者ID:bubicn,项目名称:bubichain-sdk-java,代码行数:28,代码来源:SubmitTranactionResponseConverter.java

示例10: parseFromJson

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
/**
 * Parse the jsonObject to {@link WXDomObject} recursively
 * @param map the original JSONObject
 */
public void parseFromJson(JSONObject map){
  if (map == null || map.size() <= 0) {
    return;
  }

  String type = (String) map.get("type");
  this.type = type;
  this.ref = (String) map.get("ref");
  Object style = map.get("style");
  if (style != null && style instanceof JSONObject) {
    WXStyle styles = new WXStyle();
    WXJsonUtils.putAll(styles, (JSONObject) style);
    this.style = styles;
  }
  Object attr = map.get("attr");
  if (attr != null && attr instanceof JSONObject) {
    WXAttr attrs = new WXAttr();
    WXJsonUtils.putAll(attrs, (JSONObject) attr);
    this.attr = attrs;
  }
  Object event = map.get("event");
  if (event != null && event instanceof JSONArray) {
    WXEvent events = new WXEvent();
    JSONArray eventArray = (JSONArray) event;
    int count = eventArray.size();
    for (int i = 0; i < count; ++i) {
      events.add(eventArray.getString(i));
    }
    this.event = events;
  }

}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:37,代码来源:WXDomObject.java

示例11: permission

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
@ApiOperation(value = "用户权限")
@RequiresPermissions("upms:user:permission")
@RequestMapping(value = "/permission/{id}", method = RequestMethod.POST)
@ResponseBody
public Object permission(
        @PathVariable("id") int id,
        @RequestParam(required = true,  value = "datas") String jsonDatas) {
    JSONArray datas = JSONArray.parseArray(jsonDatas);
    upmsUserPermissionService.permission(datas, id);
    return new UpmsResult(UpmsResultConstant.SUCCESS, datas.size());
}
 
开发者ID:sunzhen086,项目名称:lambo,代码行数:12,代码来源:UpmsUserController.java

示例12: test_stackTrace

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void test_stackTrace() throws Exception {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String text = JSON.toJSONString(stackTrace, SerializerFeature.WriteClassName);
    JSONArray array = (JSONArray) JSON.parse(text);
    for (int i = 0; i < array.size(); ++i) {
        StackTraceElement element = (StackTraceElement) array.get(i);
        Assert.assertEquals(stackTrace[i].getFileName(), element.getFileName());
        Assert.assertEquals(stackTrace[i].getLineNumber(), element.getLineNumber());
        Assert.assertEquals(stackTrace[i].getClassName(), element.getClassName());
        Assert.assertEquals(stackTrace[i].getMethodName(), element.getMethodName());
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:StackTraceElementTest.java

示例13: parseArray

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public static LinkedHashMap<String,BundleListing.BundleInfo> parseArray(String listingStr,LinkedHashMap<String,BundleListing.BundleInfo>currentBundleInfo) throws Exception{
    LinkedHashMap<String,BundleListing.BundleInfo> infos= new LinkedHashMap<>();
    JSONArray array = JSON.parseArray(listingStr);
    for(int x=0; x<array.size(); x++){
        JSONObject object = array.getJSONObject(x);
        BundleListing.BundleInfo info = new BundleListing.BundleInfo();
        info.setName(object.getString("name"));
        info.setPkgName(object.getString("pkgName"));
        info.setApplicationName(object.getString("applicationName"));
        info.setVersion(object.getString("version"));
        info.setDesc(object.getString("desc"));
        info.setUrl(object.getString("url"));
        info.setMd5(object.getString("md5"));
        String uniqueTag = object.getString("unique_tag");
        if(StringUtils.isEmpty(uniqueTag)){
            throw new IOException("uniqueTag is empty");
        }
        info.setUnique_tag(object.getString("unique_tag"));
        if (currentBundleInfo==null) {
            info.setCurrent_unique_tag(info.getUnique_tag());
        }else {
            if (currentBundleInfo.get(info.getPkgName())!= null){
                info.setCurrent_unique_tag(currentBundleInfo.get(info.getPkgName()).getUnique_tag());
            }
        }

        infos.put(info.getPkgName(),info);

    }
    return infos.size()>0 ? infos : null;
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:32,代码来源:BundleListingUtil.java

示例14: scan

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
/**
 * 定时扫描远程配置信息
 */
private boolean scan() {

    String listUrl = url + "/list";
    String jsonString = httpGet(listUrl);

    if (StringUtils.isBlank(jsonString)) {
        LogKit.error("can not get remote config info,plase check url : " + listUrl);
        return false;
    }

    JSONArray jsonArray = null;
    try {
        jsonArray = JSON.parseArray(jsonString);
    } catch (Throwable ex) {
        LogKit.error("can not parse json : \n" + jsonString + "\n\nfrom url : " + listUrl, ex);
        return false;
    }

    for (int i = 0; i < jsonArray.size(); i++) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        curScan.put(jsonObject.getString("id"), jsonObject.getString("version"));
    }

    return true;

}
 
开发者ID:yangfuhai,项目名称:jboot,代码行数:30,代码来源:ConfigRemoteReader.java

示例15: getUserData

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
/**
	 * 根据用户身份证号获取用户数据
	 * @return
	 */
	@RequestMapping(value = "/data")
	@ResponseBody
	public PageData getUserData(@RequestBody PageData pd) throws Exception {
//		if(StringUtils.isBlank(pd.getString("IDCARD"))){
//			return WebResult.requestFailed(10001, "参数缺失!", null);
//		}else{
			HashMap<String,String> params = new HashMap<String,String> ();
			params.put("idCardNo", "371323199401023411");
			params.put("idCardNo", pd.getString("IDCARD"));
			List<UHeader> headerList = new ArrayList<UHeader>();
			UHeader conType = new UHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
			headerList.add(conType);
			String result = HttpUtils.getPostResponse(tjUrl, params, headerList);
			if(!"".equals(result)){
				result = Des.decrypt(result);
				HashMap mp = JSON.parseObject(result, HashMap.class);
				JSONArray datalist = (JSONArray) mp.get("dataList");
				List dataList= new ArrayList();
				for(int i=0;i<datalist.size();i++){
					dataList.add(JSON.parseObject(((JSONObject)datalist.get(i)).toJSONString(),HashMap.class));
				}
				try {
					listSort(dataList);
					if(dataList.size()>0){
						dataList.get(0);
						return WebResult.requestSuccess(dataList.get(0));
					}else{
						return WebResult.requestSuccess(null);
					}
				} catch (Exception e) {
//					e.printStackTrace();
					return WebResult.requestFailed(100, "排序失败!", null);
				}
			}else{
				return WebResult.requestSuccess(null);
			}
//		}
	}
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:43,代码来源:AppUserHealthRestful.java


注:本文中的com.alibaba.fastjson.JSONArray.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。