本文整理汇总了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);
}
}
示例2: test_for_bug
import com.alibaba.fastjson.JSONArray; //导入方法依赖的package包/类
public void test_for_bug() throws Exception {
String aa = "[{\"dictFont\":\"\",\"dictId\":\"wap\",\"dictName\":\"无线&手淘\"},{\"dictFont\":\"\",\"dictId\":\"etao\",\"dictName\":\"搜索\"}]";
JSONObject jsonResult = new JSONObject();
JSONArray jsonArray = JSONArray.parseArray(aa);
jsonResult.put("aaa", jsonArray);
System.out.println(jsonResult);
}
示例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;
}
示例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;
}
}
示例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");
}
示例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());
}
示例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);// 这一步出错
}
示例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);
}
示例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());
}
示例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);
}
}
示例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: 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);
}
}
示例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);
}
}
}
示例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;
}
示例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));
}