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


Java JSONArray类代码示例

本文整理汇总了Java中net.sf.json.JSONArray的典型用法代码示例。如果您正苦于以下问题:Java JSONArray类的具体用法?Java JSONArray怎么用?Java JSONArray使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JSONArray类属于net.sf.json包,在下文中一共展示了JSONArray类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateMosaic

import net.sf.json.JSONArray; //导入依赖的package包/类
/**
 * validate the mosaic and quantity
 * @param address
 * @param mosaicName
 * @param mosaicQuantity
 * @param mosaicFeeInformation
 * @return
 */
private static String validateMosaic(String address, String mosaicName, String mosaicQuantity, MosaicFeeInformation mosaicFeeInformation) {
	String queryResult = HttpClientUtils.get(Constants.URL_ACCOUNT_MOSAIC_OWNED + "?address=" + address);
	JSONObject json = JSONObject.fromObject(queryResult);
	JSONArray array = json.getJSONArray("data");
	for(int i=0;i<array.size();i++){
		JSONObject item = array.getJSONObject(i);
		// get mosaic id
		JSONObject mosaicId = item.getJSONObject("mosaicId");
		String namespaceId = mosaicId.getString("namespaceId");
		String name = mosaicId.getString("name");
		// get mosaic quantity
		long quantity = item.getLong("quantity");
		if(mosaicName.equals(namespaceId+":"+name)){
			Double mQuantity = Double.valueOf(mosaicQuantity).doubleValue() * Math.pow(10, mosaicFeeInformation.getDivisibility());
			if(mQuantity.longValue()>quantity){
				return "insufficient mosaic quantity";
			} else {
				return null;
			}
		}
	}
	return "there is no mosaic ["+mosaicName+"] in the account";
}
 
开发者ID:NEMChina,项目名称:nem-apps,代码行数:32,代码来源:ImplInitMultisigTransaction.java

示例2: test_xml

import net.sf.json.JSONArray; //导入依赖的package包/类
public void test_xml() throws Exception {
    XMLSerializer xmlSerializer = new XMLSerializer();
    
    JSONObject json = new JSONObject();
    json.put("id", 123);
    json.put("name", "jobs");
    json.put("flag", true);
    
    JSONArray items = new JSONArray();
    items.add("x");
    items.add(234);
    items.add(false);
    json.put("items", items);
    
    String text = xmlSerializer.write(json);
    System.out.println(text);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:JSONLibXmlTest.java

示例3: list

import net.sf.json.JSONArray; //导入依赖的package包/类
/**
 * @param page
 * @param rows
 * @param s_user
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/list")
public String list(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, User s_user, HttpServletResponse response) throws Exception {
    Map<String, Object> map = new HashMap<String, Object>();
    if (page != null && rows != null) {
        PageBean pageBean = new PageBean(Integer.parseInt(page),
                Integer.parseInt(rows));
        map.put("start", pageBean.getStart());
        map.put("size", pageBean.getPageSize());
    }
    map.put("userName", StringUtil.formatLike(s_user.getUserName()));
    List<User> userList = userService.findUser(map);
    Long total = userService.getTotalUser(map);
    JSONObject result = new JSONObject();
    JSONArray jsonArray = JSONArray.fromObject(userList);
    result.put("rows", jsonArray);
    result.put("total", total);
    log.info("request: user/list , map: " + map.toString());
    ResponseUtil.write(response, result);
    return null;
}
 
开发者ID:ZHENFENG13,项目名称:ssm-demo,代码行数:29,代码来源:UserController.java

示例4: map2jsonConverter

import net.sf.json.JSONArray; //导入依赖的package包/类
/**
 * Converts a Map Object into JSON string.
 * @param hm
 * @return
 */
public static String map2jsonConverter(Map hm) {
    if (hm==null || hm.size()==0) {
        return "{}";
    }
    JSONObject jo = new JSONObject();
    for (Iterator it = hm.keySet().iterator(); it.hasNext();) {
        Object k = it.next();
        if (hm.get(k)==null || hm.get(k) instanceof String) {
            jo.accumulate(k.toString(), hm.get(k));
        } else if (hm.get(k) instanceof Collection || hm.get(k).getClass().isArray()) {
            jo.accumulate(k.toString(), JSONArray.fromObject(hm.get(k)).toString());
        } else {
            log.debug("map2jsonConverter: "+hm.get(k).getClass().getName());
            jo.accumulate(k.toString(), JSONObject.fromObject(hm.get(k)).toString());
        }
    }
    return jo.toString();
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:24,代码来源:JSONHelper.java

示例5: getDiscussList

import net.sf.json.JSONArray; //导入依赖的package包/类
public ArrayList<Discuss> getDiscussList(){
	ArrayList<Discuss> discussesList=new ArrayList<Discuss>();
	//用psessionid合成一个完整的URL并且访问它,并将结果解析为json
	JSONObject result=JSONObject.fromObject(utils.get(URL.URL_GET_DISCUSS_LIST.replace("[var]",credential.getPsessionID()).replace("[var1]",credential.getVfWebQQ()),new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result");
	//获取讨论组列表
	JSONArray discussesListInfo=result.getJSONArray("dnamelist");
	//构造讨论组列表
	for(int i=0;i<discussesListInfo.size();i++){
		JSONObject tempDiscussInfo=JSONObject.fromObject(discussesListInfo.get(i));
		//取出讨论组id,构造一个讨论组,credential用于获取成员列表
		Discuss tempDiscuss=new Discuss(tempDiscussInfo.getLong("did"),credential);
		//设置讨论组的名称
		tempDiscuss.setName(tempDiscussInfo.getString("name"));
		//添加到list内
		discussesList.add(tempDiscuss);
	}
	return discussesList;
}
 
开发者ID:KittenDev,项目名称:WebQQAPI,代码行数:19,代码来源:Account.java

示例6: requestParams2json

import net.sf.json.JSONArray; //导入依赖的package包/类
/**
 * Convert the request parameter map to a json string. 
 * @param request
 * @return
 */
public static String requestParams2json(ServletRequest request) {
    Map<String, String[]> params = request.getParameterMap();
    JSONObject jo = new JSONObject();
    for (Iterator<String> it=params.keySet().iterator(); it.hasNext();) {
        String k = it.next();
        String[] v = params.get(k);
        if (v==null || v.length==0) {
            continue;
        } else if (v.length==1) {
            jo.accumulate(k, v[0]);
        } else {
            jo.accumulate(k, JSONArray.fromObject(v));
        }
    }
    return jo.toString();
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:22,代码来源:JSONHelper.java

示例7: getDTOArray

import net.sf.json.JSONArray; //导入依赖的package包/类
/**
 * 从一个JSON数组得到一个java对象数组,形如: [{"id" : idValue, "name" : nameValue}, {"id" :
 * idValue, "name" : nameValue}, ...]
 * 
 * @param object
 * @param clazz
 * @return
 */
public static Object[] getDTOArray(String jsonString, Class<?> clazz) {
	setDataFormat2JAVA();
	JSONArray array = JSONArray.fromObject(jsonString);
	Object[] obj = new Object[array.size()];
	for (int i = 0; i < array.size(); i++) {
		JSONObject jsonObject = array.getJSONObject(i);
		obj[i] = JSONObject.toBean(jsonObject, clazz);
	}
	return obj;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:19,代码来源:JSONUtil.java

示例8: getJSONString

import net.sf.json.JSONArray; //导入依赖的package包/类
/**
 * 把数据对象转换成json字符串 DTO对象形如:{"id" : idValue, "name" : nameValue, ...}
 * 数组对象形如:[{}, {}, {}, ...] map对象形如:{key1 : {"id" : idValue, "name" :
 * nameValue, ...}, key2 : {}, ...}
 * 
 * @param object
 * @return
 */
public static String getJSONString(Object object) throws Exception {
	String jsonString = null;
	// 日期值处理器
	JsonConfig jsonConfig = new JsonConfig();
	if (object != null) {
		if (object instanceof Collection || object instanceof Object[]) {
			jsonString = JSONArray.fromObject(object, jsonConfig)
					.toString();
		} else {
			jsonString = JSONObject.fromObject(object, jsonConfig)
					.toString();
		}
	}
	return jsonString == null ? "{}" : jsonString;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:24,代码来源:JSONUtil.java

示例9: insert

import net.sf.json.JSONArray; //导入依赖的package包/类
@RequestMapping(value = ACTION_INSERT, method = RequestMethod.GET)
public String insert(HttpServletRequest request,
		HttpServletResponse response, Object object) {
	Iterator<?> it = request.getParameterMap().entrySet().iterator();
	KettleSpoon entity = new KettleSpoon();
	while (it.hasNext()) {
		Map.Entry<?, ?> ent = (Entry<?, ?>) it.next();
		entity.setValue((String) ent.getKey(),
				((String[]) ent.getValue())[0]);
	}
	entity.setParams(JSONArray.fromObject(entity.getValue()).toString());
	request.setAttribute(ENTITY, entity);
	List<?> list = service.iQuartzGroupService
			.selectByWhere(new QuartzGroup());
	request.setAttribute(LIST, list);
	return VIEW_WIDGET + VIEW_QUARTZ + PAGE_INSERT;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:18,代码来源:QuartzController.java

示例10: insert

import net.sf.json.JSONArray; //导入依赖的package包/类
@RequestMapping(value = ACTION_INSERT, method = RequestMethod.POST)
public String insert(HttpServletRequest request,
		HttpServletResponse response) throws IOException {
	Iterator<?> it = request.getParameterMap().entrySet().iterator();
	final KettleSpoon entity = new KettleSpoon();
	while (it.hasNext()) {
		Map.Entry<?, ?> ent = (Entry<?, ?>) it.next();
		entity.setValue((String) ent.getKey(),
				((String[]) ent.getValue())[0]);
	}
	entity.setParams(JSONArray.fromObject(entity.getValue()).toString());
	entity.setTest(true);
	entity.setQueue(false);
	service.iKettleSpoonService.insert(entity);
	new Thread(new Runnable() {
		@Override
		public void run() {
			service.iKettleSpoonService.execute(entity);
		}
	}).start();
	return REDIRECT + VIEW_WIDGET + VIEW_KETTLE + VIEW_SPOON + ACTION_LIST;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:23,代码来源:KettleSpoonController.java

示例11: update

import net.sf.json.JSONArray; //导入依赖的package包/类
@RequestMapping(value = ACTION_UPDATE, method = RequestMethod.POST)
public String update(HttpServletRequest request,
		HttpServletResponse response) throws IOException {
	Iterator<?> it = request.getParameterMap().entrySet().iterator();
	final KettleSpoon entity = new KettleSpoon();
	while (it.hasNext()) {
		Map.Entry<?, ?> ent = (Entry<?, ?>) it.next();
		entity.setValue((String) ent.getKey(),
				((String[]) ent.getValue())[0]);
	}
	entity.setParams(JSONArray.fromObject(entity.getValue()).toString());
	entity.setTest(true);
	entity.setQueue(false);
	service.iKettleSpoonService.update(entity);
	new Thread(new Runnable() {
		@Override
		public void run() {
			service.iKettleSpoonService.execute(entity);
		}
	}).start();
	return REDIRECT + VIEW_WIDGET + VIEW_KETTLE + VIEW_SPOON + ACTION_LIST;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:23,代码来源:KettleSpoonController.java

示例12: tree

import net.sf.json.JSONArray; //导入依赖的package包/类
@RequestMapping(value = ACTION_TREE, method = RequestMethod.POST)
public void tree(HttpServletRequest request, HttpServletResponse response)
		throws IOException {
	try {
		Iterator<?> it = request.getParameterMap().entrySet().iterator();
		KettleRepos entity = new KettleRepos();
		while (it.hasNext()) {
			Map.Entry<?, ?> ent = (Entry<?, ?>) it.next();
			entity.setValue((String) ent.getKey(),
					((String[]) ent.getValue())[0]);
		}
		List<?> list = service.iKettleReposService.getJobAndTrans(entity);
		response.getWriter().write(JSONArray.fromObject(list).toString());
	} catch (KettleException e) {
		e.printStackTrace();
	} finally {
		response.getWriter().close();
	}
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:20,代码来源:KettleSpoonController.java

示例13: getVideoNumber

import net.sf.json.JSONArray; //导入依赖的package包/类
public int getVideoNumber(String jsonContent) throws Exception {
	JSONArray array = JSONArray.fromObject(jsonContent);
	JSONObject object = null;
	int l = array.size();
	int videoNumber = 0;
	for (int i = 0; i < l; i++) {
		object = array.getJSONObject(i);
		JSONObject obj1 = (JSONObject) object.get("data");
		JSONObject obj2 = (JSONObject) obj1.get("page");
		videoNumber = Integer.parseInt(obj2.get("count").toString());
	}
	return videoNumber;
}
 
开发者ID:bighuang624,项目名称:BiliInfoCrawler,代码行数:14,代码来源:Test.java

示例14: getFriendList

import net.sf.json.JSONArray; //导入依赖的package包/类
/**
 * 获取好友列表相当于组里的所有人
 * 
 * @param userGroupTopId
 *            组id
 * @param token
 *            身份
 * @return
 */
public static List<UserData> getFriendList(String userGroupTopId, String token) {
	JSONObject js = new JSONObject();
	js.put("hOpCode", "13");
	js.put("userGroupTopId", userGroupTopId);
	Map<String, String> header = new HashMap<>();
	header.put("hOpCode", "13");
	header.put("token", token);
	byte[] returnByte = HttpUtil.send(js.toString(), CommonConfigChat.IDENTITY_URL, header, HttpUtil.POST);
	if (returnByte != null) {
		String str = null;
		try {
			str = new String(returnByte, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			WSManager.log.error("返回字符串解析异常", e);
		}
		JSONObject returnjs = JSONObject.fromObject(str);
		// 如果返回的是错误类型,说明用户中心拦截器没通过
		if (returnjs.getString("hOpCode").equals("0")) {
			return null;
		}
		JSONArray jsArray = returnjs.getJSONArray("user");
		List<UserData> list = new ArrayList<>();
		for (int i = 0; i < jsArray.size(); i++) {
			JSONObject user = jsArray.getJSONObject(i);
			UserData userData = new UserData(user);
			list.add(userData);
		}
		return list;
	}
	return null;
}
 
开发者ID:dianbaer,项目名称:anychat,代码行数:41,代码来源:IdentityAction.java

示例15: list

import net.sf.json.JSONArray; //导入依赖的package包/类
/**
 * 查找相应的数据集合
 * 
 * @param page
 * @param rows
 * @param article
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/list")
public String list(
		@RequestParam(value = "page", required = false) String page,
		@RequestParam(value = "rows", required = false) String rows,
		Article article, HttpServletResponse response) throws Exception {
	Map<String, Object> map = new HashMap<String, Object>();
	if (page != null && rows != null) {
		PageBean pageBean = new PageBean(Integer.parseInt(page),
				Integer.parseInt(rows));
		map.put("start", pageBean.getStart());
		map.put("size", pageBean.getPageSize());
	}
	if (article != null) {
		map.put("articleTitle",
				StringUtil.formatLike(article.getArticleTitle()));
	}
	List<Article> articleList = articleService.findArticle(map);
	Long total = articleService.getTotalArticle(map);
	JSONObject result = new JSONObject();
	JSONArray jsonArray = JSONArray.fromObject(articleList);
	result.put("rows", jsonArray);
	result.put("total", total);
	ResponseUtil.write(response, result);
	log.info("request: article/list , map: " + map.toString());
	return null;
}
 
开发者ID:ZHENFENG13,项目名称:ssm-demo,代码行数:37,代码来源:ArticleController.java


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