當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。