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


Java JSONArray.parseArray方法代码示例

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


在下文中一共展示了JSONArray.parseArray方法的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_for_bug

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void test_for_bug() throws Exception {
    String aa = "[{\"dictFont\":\"&#xe62b;\",\"dictId\":\"wap\",\"dictName\":\"无线&手淘\"},{\"dictFont\":\"&#xe62a;\",\"dictId\":\"etao\",\"dictName\":\"搜索\"}]";
    JSONObject jsonResult = new JSONObject();
    JSONArray jsonArray = JSONArray.parseArray(aa);
    jsonResult.put("aaa", jsonArray);

    System.out.println(jsonResult);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:9,代码来源:Bug_for_liuying.java

示例3: queryUserVisit

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
/**
 * 根据shopId读取table_user_visit中的最新数据
 *
 * 利用redis list的trim删去已经读的数据
 */

public List<UserVisitBean> queryUserVisit(List<Integer> shopIdlist) throws Exception {


    //在push数据的时候要采用rpush
    long size = redisTemplate.opsForList().size(TABLE_USER_VISIT_KEY);
    List<Object> tempList = redisTemplate.opsForList().range(TABLE_USER_VISIT_KEY, 0, 1);
    //List<Object> tempList = redisTemplate.opsForList().range(TABLE_USER_VISIT_KEY, 0, size);
    List<UserVisitBean> resList = JSONArray.parseArray(tempList.toString(), UserVisitBean.class);
    //redisTemplate.opsForList().trim(TABLE_USER_VISIT_KEY, size, -1);
    redisTemplate.opsForList().trim(TABLE_USER_VISIT_KEY, 1, -1);
    if (resList.isEmpty()) {
        return null;
    }
    //筛选特定shop_id的记录
    Iterator<UserVisitBean> iterator = resList.iterator();
    while (iterator.hasNext()) {
        UserVisitBean userVisitBean = iterator.next();
        if (!shopIdlist.contains(userVisitBean.getShopId())) {
            iterator.remove();
        }
    }
    return resList;

}
 
开发者ID:wanghan0501,项目名称:WiFiProbeAnalysis,代码行数:31,代码来源:UserVisitMapperImpl.java

示例4: getInfoMany

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
/**获取存储信息*/
@SuppressWarnings("unchecked")
public <T> List<T> getInfoMany(long memberId, String key,Class<T> clazz){
	try {
		if(memberId != ReturnUtil.NOT_LOGIN_CODE) key += memberId;
		Object obj = null;
		if(session!=null){
			obj = session.getAttribute(key);
		}else{
			obj = JSONArray.parseArray(RedisUtil.getJedis().get(key));
		}
		return (List<T>) obj;
	} catch (Exception e) {
		System.out.println("【获取存储信息】异常:"+e.toString());
		return null;
	}
}
 
开发者ID:zhiqiang94,项目名称:BasicsProject,代码行数:18,代码来源:StorageUtil.java

示例5: saveObject

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void saveObject(DataGroup dataGroup) throws Exception {
    GroupData groupData = new GroupData();
    Calendar cal = Calendar.getInstance();
    Date date = cal.getTime();
    String time_id = new SimpleDateFormat("yyyyMMDDHHmmssSSS").format(date) + "-" + dataGroup.getId();
    System.out.println(time_id);
    groupData.setTime_id(time_id);
    groupData.setRecord_time(dataGroup.getTime());
    groupData.setAddr(dataGroup.getAddr());
    JSONArray ja = JSONArray.parseArray(JSON.toJSONString(dataGroup.getData()));
    groupData.setDataList(ja.toJSONString());
    groupData.setProbe_id(dataGroup.getId());
    groupData.setLat(dataGroup.getLat());
    groupData.setLon(dataGroup.getLon());
    groupData.setMmac(dataGroup.getMmac());
    groupData.setWmac(dataGroup.getWmac());
    groupData.setWssid(dataGroup.getWssid());
    groupData.setRate(dataGroup.getRate());
    try {
        groupDataDao.save(groupData);
    }catch(Exception e){
        e.printStackTrace();
    }
    System.out.println("Insert Into Hbase Success");
}
 
开发者ID:wanghan0501,项目名称:WiFiProbeAnalysis,代码行数:26,代码来源:DataUploadServiceImpl.java

示例6: test_for_issue

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void test_for_issue() throws Exception {
    Date now = new Date();

    GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
    gregorianCalendar.setTime(now);

    XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);

    String jsonString = JSON.toJSONString(calendar);
    // success
    calendar = JSON.parseObject(jsonString, XMLGregorianCalendar.class);

    Object toJSON1 = JSON.toJSON(calendar); // debug看到是 Long 类型
    // 所以这里会报错:
    // error: java.lang.ClassCastException: java.lang.Long cannot be cast to com.alibaba.fastjson.JSONObject
    //JSONObject jsonObject = (JSONObject) JSON.toJSON(calendar);
    // 所以 这里肯定会报错, 因为 jsonObject 不是JSONObject类型
    //calendar = jsonObject.toJavaObject(XMLGregorianCalendar.class);

    List<XMLGregorianCalendar> calendarList = new ArrayList<XMLGregorianCalendar>();
    calendarList.add(calendar);
    calendarList.add(calendar);
    calendarList.add(calendar);

    Object toJSON2 = JSON.toJSON(calendarList); // debug 看到是 JSONArray 类型

    // success: 通过 JSONArray.parseArray 方法可以正确转换
    JSONArray jsonArray = (JSONArray) JSON.toJSON(calendarList);
    jsonString = jsonArray.toJSONString();
    List<XMLGregorianCalendar> calendarList1 = JSONArray.parseArray(jsonString, XMLGregorianCalendar.class);

    // 通过 jsonArray.toJavaList 无法转换
    // error: com.alibaba.fastjson.JSONException: can not cast to : javax.xml.datatype.XMLGregorianCalendar
    List<XMLGregorianCalendar> calendarList2 = jsonArray.toJavaList(XMLGregorianCalendar.class);
    assertNotNull(calendarList2);
    assertEquals(3, calendarList2.size());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:38,代码来源:Issue1023.java

示例7: testParseArray

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
@Test
public void testParseArray() throws Exception {
    List list = new ArrayList();
    OuterEntry entry = new OuterEntry();
    list.add(entry);
    entry.setId(1000L);
    entry.setUrl("http://www.springframework.org/schema/aop");
    String jsonString = JSONObject.toJSONString(entry);
    String arrayString = JSONObject.toJSONString(list);
    System.out.println(jsonString);
    System.out.println(arrayString);
    list = JSONArray.parseArray(arrayString, OuterEntry.class);
    JSONArray array = JSONArray.parseArray(arrayString);// 这一步出错
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:JSONTest.java

示例8: permission

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
@ApiOperation(value = "角色权限")
@RequiresPermissions("upms:role:permission")
@RequestMapping(value = "/permission/{id}", method = RequestMethod.POST)
@ResponseBody
public Object permission(@PathVariable("id") int id, HttpServletRequest request) {
    JSONArray datas = JSONArray.parseArray(request.getParameter("datas"));
    int result = upmsRolePermissionService.rolePermission(datas, id);
    return new UpmsResult(UpmsResultConstant.SUCCESS, result);
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:10,代码来源:UpmsRoleController.java

示例9: 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, HttpServletRequest request) {
    JSONArray datas = JSONArray.parseArray(request.getParameter("datas"));
    upmsUserPermissionService.permission(datas, id);
    return new UpmsResult(UpmsResultConstant.SUCCESS, datas.size());
}
 
开发者ID:youngMen1,项目名称:-Spring-SpringMVC-Mybatis-,代码行数:10,代码来源:UpmsUserController.java

示例10: json2List

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
/**
 * @param message
 * @param clz
 * @return
 * @throws CommonException
 */
public static <T> List<T> json2List(String message, Class<T> clz) throws CommonException {
	String errorMessage = "The operation of jsonToList has been error!";
	try {
		return (List<T>) JSONArray.parseArray(message, clz);
	} catch (Exception e) {
		throw new CommonException(errorMessage, e);
	}
}
 
开发者ID:swxiao,项目名称:bubble2,代码行数:15,代码来源:BeanUtils.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: json2array

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public IArray json2array(String jsonStr) {
    if (jsonStr.length() < 2) {
        throw new IllegalStateException(
                "Can\'t decode AVAObject. JSON String is too short. Len: " + jsonStr.length());
    } else {
        JSONArray jsa = JSONArray.parseArray(jsonStr);
        return this.decodeSFSArray((JSONArray) jsa);
    }
}
 
开发者ID:zerosoft,项目名称:CodeBroker,代码行数:10,代码来源:DefaultSFSDataSerializer.java

示例13: loadPositions

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void loadPositions(String json) {

        if (StringHelper.isEmpty(json)) {
            return;
        }

        Long inode = 0L, pos = 0L, number = 0L;
        String file = "";
        JSONArray positionRecords = JSONArray.parseArray(json);
        for (int i = 0; i < positionRecords.size(); i++) {
            JSONObject positionObject = (JSONObject) positionRecords.get(i);
            inode = positionObject.getLong("inode");
            pos = positionObject.getLong("pos");
            file = positionObject.getString("file");
            // add line number
            number = positionObject.getLongValue("num");
            for (Object v : Arrays.asList(inode, pos, file)) {
                Preconditions.checkNotNull(v, "Detected missing value in position file. " + "inode: " + inode
                        + ", pos: " + pos + ", path: " + file);
            }
            TailFile tf = tailFiles.get(inode);
            try {
                if (tf != null && tf.updatePos(file, inode, pos, number)) {
                    tailFiles.put(inode, tf);
                }
                else {
                    // add old tail file into memory
                    maybeReloadMap.put(inode, new Long[] { pos, number });
                    if (log.isDebugEnable()) {
                        log.debug(this, "add old&inInterrupt file: " + file + ", inode: " + inode + ", pos: " + pos);
                    }

                }
            }
            catch (IOException e) {
                log.err(this, "TailFile updatePos FAILED.", e);
            }
        }
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:40,代码来源:ReliableTaildirEventReader.java

示例14: getAnnouncements

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public static List<Announcement> getAnnouncements(String teamId, String announce, int limit) {
    if (TextUtils.isEmpty(announce)) {
        return null;
    }

    List<Announcement> announcements = new ArrayList<>();
    try {
        int count = 0;
        JSONArray jsonArray = JSONArray.parseArray(announce);
        for (int i = jsonArray.size() - 1; i >= 0; i--) {
            JSONObject json = jsonArray.getJSONObject(i);
            String id = json.getString(JSON_KEY_ID);
            String creator = json.getString(JSON_KEY_CREATOR);
            String title = json.getString(JSON_KEY_TITLE);
            long time = json.getLongValue(JSON_KEY_TIME);
            String content = json.getString(JSON_KEY_CONTENT);

            announcements.add(new Announcement(id, teamId, creator, title, time, content));

            if (++count >= limit) {
                break;
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return announcements;
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:30,代码来源:AnnouncementHelper.java

示例15: test_0

import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void test_0() throws Exception {
    List<String> typeList = JSONArray.parseArray("['java.lang.Class','java.lang.Long']", String.class);
    Assert.assertEquals("java.lang.Class", typeList.get(0));
    Assert.assertEquals("java.lang.Long", typeList.get(1));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:Bug_8.java


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