本文整理汇总了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);
}
}
示例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));
}
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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");
}
示例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;
}
}
示例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());
}
示例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());
}
}
示例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;
}
示例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;
}
示例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);
}
// }
}