當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONArray類代碼示例

本文整理匯總了Java中com.alibaba.fastjson.JSONArray的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray類的具體用法?Java JSONArray怎麽用?Java JSONArray使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JSONArray類屬於com.alibaba.fastjson包,在下文中一共展示了JSONArray類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getObject

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
/**
 * read the json file and transform into memory
 *
 * @return
 * @throws Exception
 */
public Map<String, Map<String, String>> getObject() throws Exception {
    Map<String, Map<String, String>> result = new ConcurrentHashMap<String, Map<String, String>>();
    String jsonString = readFromFile();
    JSONArray jsonArray = JSONObject.parseArray(jsonString);
    if (jsonArray != null) {
        for (Object schema : jsonArray) {
            JSONObject x = (JSONObject) schema;
            String schemaName = x.getString("schema");
            JSONArray viewList = x.getJSONArray("list");
            Map<String, String> schemaView = new ConcurrentHashMap<String, String>();
            for (Object view : viewList) {
                JSONObject y = (JSONObject) view;
                schemaView.put(y.getString("name"), y.getString("sql"));
            }
            result.put(schemaName, schemaView);
        }
    }
    return result;
}
 
開發者ID:actiontech,項目名稱:dble,代碼行數:26,代碼來源:FileSystemRepository.java

示例2: test_for_issue

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
public void test_for_issue() throws Exception {
    DubboResponse resp = new DubboResponse();

    // test for JSONObject
    JSONObject obj = new JSONObject();
    obj.put("key1","value1");
    obj.put("key2","value2");
    resp.setData(obj);

    String str = JSON.toJSONString(resp);
    System.out.println(str);
    DubboResponse resp1 = JSON.parseObject(str, DubboResponse.class);
    assertEquals(str, JSON.toJSONString(resp1));

    // test for JSONArray
    JSONArray arr = new JSONArray();
    arr.add("key1");
    arr.add("key2");
    resp.setData(arr);

    String str2 = JSON.toJSONString(resp);
    System.out.println(str2);
    DubboResponse resp2 = JSON.parseObject(str2, DubboResponse.class);
    assertEquals(str2, JSON.toJSONString(resp2));

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:Issue1492.java

示例3: testClone

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
@Test
public void testClone() throws Exception {
  JSONObject.parseObject("{\"ref\":\"100\",\"type\":\"div\",\"attr\":{},\"style\":{\"backgroundColor\":\"rgb(40,96,144)\",\"fontSize\":40,\"color\":\"#ffffff\",\"paddingRight\":30,\"paddingLeft\":30,\"paddingBottom\":20,\"paddingTop\":20}}");
  JSONObject obj = new JSONObject();
  obj.put("ref","101");
  obj.put("type","test");

  JSONArray event = new JSONArray();
  event.add("click");
  obj.put("event",event);
  dom.parseFromJson(obj);

  WXDomObject clone = dom.clone();
  assertEquals(clone.getRef(),"101");
  assertEquals(clone.getType(),"test");

}
 
開發者ID:amap-demo,項目名稱:weex-3d-map,代碼行數:18,代碼來源:WXDomObjectTest.java

示例4: 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);
    }
    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) {
        Assert.assertEquals(i, ((Integer) array.get(i)).intValue()); 
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:22,代碼來源:JSONReaderScannerTest_int.java

示例5: login

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
@ApiOperation("用戶登入")
@PostMapping("/login")
public ResponseEntity login(@RequestBody @Valid IndexLoginFormat format) {
    UserEntity userEntity = userService.getUserByLogin(format.getEmail(),
            new Md5Hash(format.getPassword()).toString());
    if (userEntity == null)
        throw new WebErrorException("用戶名密碼錯誤");

    JSONArray array = userEntity.getPermission();
    Iterator<Object> it = array.iterator();
    Set<String> permission = new HashSet<>();
    while (it.hasNext()) {
        permission.add(it.next().toString());
    }
    String token = JWTUtil.sign(userEntity.getUid(), userEntity.getRole(), permission, userEntity.getPassword());
    Cache<String, String> authCache = CacheController.getAuthCache();
    authCache.put(token, userEntity.getPassword());

    return new ResponseEntity("登入成功", token);
}
 
開發者ID:Eagle-OJ,項目名稱:eagle-oj-api,代碼行數:21,代碼來源:IndexController.java

示例6: addProblem

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
public int addProblem(int owner, String title, JSONObject description, JSONObject inputFormat, JSONObject outputFormat,
                      int difficult, JSONArray samples, int time, int memory) {
    // 添加題目
    ProblemEntity problemEntity = new ProblemEntity();
    problemEntity.setOwner(owner);
    problemEntity.setTitle(title);
    problemEntity.setLang(JudgeHelper.getAllLanguages());
    problemEntity.setDescription(description);
    problemEntity.setInputFormat(inputFormat);
    problemEntity.setOutputFormat(outputFormat);
    problemEntity.setDifficult(difficult);
    problemEntity.setSamples(samples);
    problemEntity.setTime(time);
    problemEntity.setMemory(memory);
    problemEntity.setStatus(0);
    problemEntity.setCreateTime(System.currentTimeMillis());

    return problemDao.addProblem(sqlSession, problemEntity)? problemEntity.getPid() : 0;
}
 
開發者ID:Eagle-OJ,項目名稱:eagle-oj-api,代碼行數:20,代碼來源:ProblemService.java

示例7: list

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
@RequestMapping("/list")
@ResponseBody
public String list(@ModelAttribute PayOrder payOrder, Integer pageIndex, Integer pageSize) {
    PageModel pageModel = new PageModel();
    int count = payOrderService.count(payOrder);
    if(count <= 0) return JSON.toJSONString(pageModel);
    List<PayOrder> payOrderList = payOrderService.getPayOrderList((pageIndex-1)*pageSize, pageSize, payOrder);
    if(!CollectionUtils.isEmpty(payOrderList)) {
        JSONArray array = new JSONArray();
        for(PayOrder po : payOrderList) {
            JSONObject object = (JSONObject) JSONObject.toJSON(po);
            if(po.getCreateTime() != null) object.put("createTime", DateUtil.date2Str(po.getCreateTime()));
            if(po.getAmount() != null) object.put("amount", AmountUtil.convertCent2Dollar(po.getAmount()+""));
            array.add(object);
        }
        pageModel.setList(array);
    }
    pageModel.setCount(count);
    pageModel.setMsg("ok");
    pageModel.setRel(true);
    return JSON.toJSONString(pageModel);
}
 
開發者ID:ywtnhm,項目名稱:pay-xxpay-master,代碼行數:23,代碼來源:PayOrderController.java

示例8: getNewsListFromJsonArray

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
public List<Article> getNewsListFromJsonArray(JSONArray jsonArray) {
	List<Article> list = new ArrayList<>();
	int size = jsonArray.size();
	int lastindex = 0;
	if (size >= 5) {
		lastindex = 5;
	} else {
		lastindex = size;
	}
	for (int i = 0; i < lastindex; i++) {
		JSONObject object = jsonArray.getJSONObject(i);
		String id = object.getString("id");//消息內容Id
		String replaceUrl = newsUrl.replace("id", id);
		String s = HttpClientUtil.sendGet(replaceUrl, null, null);
		JSONObject jo = JSONObject.parseObject(s);
		Article article = new Article();
		article.setTitle(jo.getString("title"));
		article.setDescription("");
		article.setPicUrl(jo.getString("image"));
		article.setUrl(jo.getString("share_url"));
		list.add(article);
	}
	return list;
}
 
開發者ID:CharleyXu,項目名稱:tulingchat,代碼行數:25,代碼來源:DailyZhihuUtil.java

示例9: savePipelineState

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
private void savePipelineState(Pipeline pipeline, String state, String time) {
    State s = new State(time, state);
    Process p = searchProcessByPno(pipeline.getNo());
    if (p != null) {
        p.getPipelineState().add(s);
    } else {
        List<State> PipelineState = new ArrayList<>();
        PipelineState.add(s);
        p = new Process(pipeline.getNo(), PipelineState);
        SysConfig.ProcessList.add(p);
    }
    String processListJson = JSONArray.toJSONString(SysConfig.ProcessList);
    try {
        FileUtil.writeFile(processListJson, SysConfig.Catalog_Project + "cashe/process.txt");
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:dbiir,項目名稱:rainbow,代碼行數:19,代碼來源:RwMain.java

示例10: validateNotLike

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
/**
* 不匹配 <br/>
* @author jingma
* @param object
* @param vi
* @param validateInfo
*/
private boolean validateNotLike(Object object, JSONObject vi, JSONArray validateInfo) {
    if(object==null){
        return true;
    }
    List<String> dataList = getValidateData(vi);
    boolean result = true;
    for(String val:dataList){
        if(object.toString().indexOf(val)>-1){
            result = false;
            break;
        }
    }
    if(!result){
        vi.put(VALIDATE_VAL, object.toString());
        validateInfo.add(vi);
    }
    return result;
}
 
開發者ID:majinju,項目名稱:KettleEasyExpand,代碼行數:26,代碼來源:DataValidate.java

示例11: test_number

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
public void test_number() throws Exception {
    String text = "[0,1,-1,2E3,2E+3,2E-3,2e3,2e+3,2e-3]";
    JSONArray array = JSON.parseArray(text);

    Assert.assertEquals(0, array.get(0));
    Assert.assertEquals(1, array.get(1));
    Assert.assertEquals(-1, array.get(2));
    Assert.assertEquals(new BigDecimal("2E3"), array.get(3));
    Assert.assertEquals(new BigDecimal("2E3"), array.get(4));
    Assert.assertEquals(new BigDecimal("2E-3"), array.get(5));
    Assert.assertEquals(new BigDecimal("2E3"), array.get(6));
    Assert.assertEquals(new BigDecimal("2E3"), array.get(7));
    Assert.assertEquals(new BigDecimal("2E-3"), array.get(8));

    for (long i = Long.MIN_VALUE; i <= Long.MIN_VALUE + 1000 * 10; ++i) {
        Assert.assertEquals(i, JSON.parse(Long.toString(i)));
    }

    for (long i = Long.MAX_VALUE - 1000 * 10; i <= Long.MAX_VALUE && i > 0; ++i) {
        Assert.assertEquals(i, JSON.parse(Long.toString(i)));
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:LexerTest.java

示例12: list

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
@RequestMapping("/list")
@ResponseBody
public String list(@ModelAttribute MchNotify mchNotify, Integer pageIndex, Integer pageSize) {
    PageModel pageModel = new PageModel();
    int count = mchNotifyService.count(mchNotify);
    if(count <= 0) return JSON.toJSONString(pageModel);
    List<MchNotify> mchNotifyList = mchNotifyService.getMchNotifyList((pageIndex-1)*pageSize, pageSize, mchNotify);
    if(!CollectionUtils.isEmpty(mchNotifyList)) {
        JSONArray array = new JSONArray();
        for(MchNotify po : mchNotifyList) {
            JSONObject object = (JSONObject) JSONObject.toJSON(po);
            if(po.getCreateTime() != null) object.put("createTime", DateUtil.date2Str(po.getCreateTime()));
            if(po.getLastNotifyTime() != null) object.put("lastNotifyTime", DateUtil.date2Str(po.getLastNotifyTime()));
            array.add(object);
        }
        pageModel.setList(array);
    }
    pageModel.setCount(count);
    pageModel.setMsg("ok");
    pageModel.setRel(true);
    return JSON.toJSONString(pageModel);
}
 
開發者ID:jmdhappy,項目名稱:xxpay-master,代碼行數:23,代碼來源:MchNotifyController.java

示例13: getUserreport

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
@RequestMapping("getUserReport.do")
public void getUserreport(HttpServletResponse response){
	List<Report> list=timetableservice.getAllUserReport();
	List<Object> list_array=new ArrayList<Object>();
	
	for(Report item :list){
		list_array.add(item);
	}
	JSONArray array=new JSONArray(list_array);
	try {
		response.getWriter().print(array);
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:liberliushahe,項目名稱:attendance,代碼行數:17,代碼來源:StatisAction.java

示例14: tree

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
/**
 * 獲取所有機構列表
 * @return
 */
@ApiOperation(value = "字典管理-樹層級結構接口")
@PostMapping("/tree")
@ResponseBody
public JSONArray tree(SysDict model) {
    JSONArray list=new JSONArray();
    List<SysDict> midList = service.getDicByParentId(model.getId());
    if(midList!=null){
        for (SysDict item:midList) {
            JSONObject obj=new JSONObject();
            obj.put("name",item.getLabel());
            obj.put("id",item.getValue());
            obj.put("pId",item.getParentId());
            obj.put("isParent",""+isHaveChild(item.getId()));
            list.add(obj);
        }
    }
    return list;
}
 
開發者ID:egojit8,項目名稱:easyweb,代碼行數:23,代碼來源:DictController.java

示例15: isJSONArray

import com.alibaba.fastjson.JSONArray; //導入依賴的package包/類
/**判斷是否為JSONArray
 * @param obj instanceof String ? parseArray
 * @return
 */
public static boolean isJSONArray(Object obj) {
	if (obj instanceof JSONArray) {
		return true;
	}
	if (obj instanceof String) {
		try {
			JSONArray json = parseArray((String) obj);
			return json != null && json.isEmpty() == false;
		} catch (Exception e) {
			Log.e(TAG, "isJSONArray  catch \n" + e.getMessage());
		}
	}
	
	return false;
}
 
開發者ID:TommyLemon,項目名稱:APIJSON-Android-RxJava,代碼行數:20,代碼來源:JSON.java


注:本文中的com.alibaba.fastjson.JSONArray類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。