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