本文整理匯總了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));
}