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


Java JSONArray.fromObject方法代码示例

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


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

示例1: getDTOArray

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * 从一个JSON数组得到一个java对象数组,形如: [{"id" : idValue, "name" : nameValue}, {"id" :
 * idValue, "name" : nameValue}, ...]
 * 
 * @param object
 * @param clazz
 * @param map
 * @return
 */
public static Object[] getDTOArray(String jsonString, Class<?> clazz,
		Map<?, ?> map) {
	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, map);
	}
	return obj;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:21,代码来源:JSONUtil.java

示例2: getOption

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * replacement的value为String类型时,直接根据key替换,否则转为Json》String后再替换
 * @author ack (chenzhao)  @DATE: Aug 23, 2017 
 * @param replacement
 * @return 返回生成option字符串
 */
public  String getOption(LinkedHashMap<String, Object> replacement){
	Set<Entry<String, Object>> entrySet=replacement.entrySet();
	Iterator<Entry<String, Object>> iterator=entrySet.iterator();
	while (iterator.hasNext()) {
		Entry<String, Object>entry=(Entry<String, Object>) iterator.next();
		//如果value非String,则将value转为json再转为String
		String value=entry.getValue()+"";
		Object objValue=entry.getValue() ;
		if(!(objValue instanceof String)){
			if(objValue instanceof List||objValue instanceof Object[]){//如果是数组或集合
				JSONArray jsonArray=JSONArray.fromObject(objValue);
				value=jsonArray.toString();
			}else{
				JSONObject jsonObjecct=JSONObject.fromObject(entry.getValue());
				value=jsonObjecct.toString();
			}
		}
		//根据key替换Option字符串里的字符
		chartString=chartString.replace(entry.getKey()+"", value);
	}
	return chartString;
}
 
开发者ID:pcbaby-ch,项目名称:echarts,代码行数:29,代码来源:Echart.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: 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

示例5: list

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * @param page
 * @param rows
 * @param s_user
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/datagrid", method = RequestMethod.POST)
public String list(@RequestParam(value = "page", required = false) String page, @RequestParam(value = "rows", required = false) String rows, User s_user, HttpServletResponse response) throws Exception {
    PageBean pageBean = new PageBean(Integer.parseInt(page), Integer.parseInt(rows));
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("userName", StringUtil.formatLike(s_user.getUserName()));
    map.put("start", pageBean.getStart());
    map.put("size", pageBean.getPageSize());
    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,项目名称:perfect-ssm,代码行数:26,代码来源:UserController.java

示例6: 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

示例7: updateSex

import net.sf.json.JSONArray; //导入方法依赖的package包/类
public String updateSex() {
	
	stuList = service.loadStuList();
	// 获取男生数量和女生数量
	
	JSONArray jsonArray = JSONArray.fromObject(stuList);
	result = jsonArray.toString();
	
	try {
		response.setHeader("Cache-Control", "no-cache");
		response.setContentType("aplication/json;charset=UTF-8");
		response.getWriter().print(result);// 发送到页面
	} catch (IOException e) {
		e.printStackTrace();
	}
	
	System.out.println(result);
	return null;
}
 
开发者ID:lrxzl,项目名称:djpt,代码行数:20,代码来源:ChartAction.java

示例8: testGetDataToSend

import net.sf.json.JSONArray; //导入方法依赖的package包/类
@Test
public void testGetDataToSend() {
    System.out.println("addSample");
    LoadosophiaClient instance = new LoadosophiaClient();
    List<SampleResult> list = new LinkedList<>();
    list.add(new SampleResult(System.currentTimeMillis(), 1));
    list.add(new SampleResult(System.currentTimeMillis() + 1000, 1));
    list.add(new SampleResult(System.currentTimeMillis() + 2000, 1));
    list.add(new SampleResult(System.currentTimeMillis() + 3000, 1));
    list.add(new SampleResult(System.currentTimeMillis() + 3000, 3));
    list.add(new SampleResult(System.currentTimeMillis() + 3000, 2));
    list.add(new SampleResult(System.currentTimeMillis() + 4000, 1));
    list.add(new SampleResult(System.currentTimeMillis() + 5000, 1));
    list.add(new SampleResult(System.currentTimeMillis() + 6000, 1));

    String str = instance.getDataToSend(list).toString();
    System.out.println("JSON: " + str);
    assertFalse("[]".equals(str));
    assertFalse("".equals(str));
    JSONArray test = JSONArray.fromObject(str);
    assertEquals(7, test.size());
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:23,代码来源:LoadosophiaClientTest.java

示例9: parseString

import net.sf.json.JSONArray; //导入方法依赖的package包/类
@Override
protected String parseString(String jsonString) {
    JSONArray jsonArray = JSONArray.fromObject(jsonString);
    JSONArray segments = jsonArray.getJSONArray(0);
    StringBuilder result = new StringBuilder();

    for (int i = 0; i < segments.size(); i++) {
        result.append(segments.getJSONArray(i).getString(0));
        result.append("\r\n");
    }

    return new String(result);
}
 
开发者ID:a483210,项目名称:GoogleTranslation,代码行数:14,代码来源:GoogleTranslator.java

示例10: responseArraySuccess

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/** 
 * 返回成功 
 * @param obj 输出对象 
 * @return 输出成功的JSON格式数据 
 */  
public String responseArraySuccess(Object obj){  
    JSONArray jsonObj = null;  
    if(obj != null){  
        logger.info("后端返回对象:{}", obj);  
        JsonConfig jsonConfig = new JsonConfig();  
        jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());  
        jsonObj = JSONArray.fromObject(obj, jsonConfig);  
        logger.info("后端返回数据:" + jsonObj);  
    }  
    logger.info("输出结果:{}", jsonObj.toString());  
    return jsonObj.toString();  
}
 
开发者ID:lonelyshine,项目名称:xcx-specialty,代码行数:18,代码来源:BaseController.java

示例11: getDTOList

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * 从一个JSON数组得到一个java对象集合
 * 
 * @param object
 * @param clazz
 * @return
 */
public static List<Object> getDTOList(String jsonString, Class<?> clazz) {
	setDataFormat2JAVA();
	JSONArray array = JSONArray.fromObject(jsonString);
	List<Object> list = new ArrayList<Object>();
	for (Iterator<?> iter = array.iterator(); iter.hasNext();) {
		JSONObject jsonObject = (JSONObject) iter.next();
		list.add(JSONObject.toBean(jsonObject, clazz));
	}
	return list;
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:18,代码来源:JSONUtil.java

示例12: checkDynasty

import net.sf.json.JSONArray; //导入方法依赖的package包/类
@Action("checkDynasty")
public String checkDynasty(){
	dynastyList=bookService.checkDynasty();
	JSONArray jsonArray = JSONArray.fromObject(dynastyList);
	//ajax返回客户端
	jsonArray.toString();
	HttpServletResponse response = ServletActionContext.getResponse();
	response.setContentType("application/html;charset=UTF-8");
	try {
		response.getWriter().write(jsonArray.toString());
	} catch (IOException e) {
		e.printStackTrace();
	} 
	return null;
}
 
开发者ID:zhangjikai,项目名称:sdudoc,代码行数:16,代码来源:BookAction.java

示例13: list

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * 查找相应的数据集合
 *
 * @param page
 * @param rows
 * @param storeBook
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/list")
public String list(
        @RequestParam(value = "page", required = false) String page,
        @RequestParam(value = "rows", required = false) String rows,
        StoreBook storeBook, 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 (storeBook.getBookId() != null) {
        map.put("isbn", storeBook.getBookId() + "");
    }
    if (storeBook.getStoreId() != null) {
        map.put("storeId", storeBook.getStoreId() + "");
    }
    List<StoreBook> storeBookList = storeBookService.findStoreBooks(map);
    Long total = storeBookService.getTotalStoreBooks(map);
    JSONObject result = new JSONObject();
    JSONArray jsonArray = JSONArray.fromObject(storeBookList);
    result.put("rows", jsonArray);
    result.put("total", total);
    ResponseUtil.write(response, result);
    log.info("request: storeBook/list , map: " + map.toString());
    return null;
}
 
开发者ID:ZHENFENG13,项目名称:ssm-demo,代码行数:39,代码来源:StoreBookController.java

示例14: list

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * 查找相应的数据集合
 *
 * @param page
 * @param rows
 * @param store
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping("/list")
public String list(
        @RequestParam(value = "page", required = false) String page,
        @RequestParam(value = "rows", required = false) String rows,
        Store store, 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 (store.getStatus() != 0) {
        map.put("status", store.getStatus() + "");
    }
    if (store.getNumber() != null) {
        map.put("number", store.getNumber());
    }
    List<Store> storeList = storeService.findStores(map);
    Long total = storeService.getTotalStores(map);
    JSONObject result = new JSONObject();
    JSONArray jsonArray = JSONArray.fromObject(storeList);
    result.put("rows", jsonArray);
    result.put("total", total);
    ResponseUtil.write(response, result);
    log.info("request: store/list , map: " + map.toString());
    return null;
}
 
开发者ID:ZHENFENG13,项目名称:ssm-demo,代码行数:39,代码来源:StoreController.java

示例15: toList

import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
 * json To List<?>
 * @param jsonStr
 * @param objClass
 * @return
 */
@SuppressWarnings("deprecation")
public static List<?> toList(final String jsonStr,Class<?> objClass){
	  JSONArray jsArray = JSONArray.fromObject(jsonStr);
	  List<?> list = JSONArray.toList(jsArray, objClass);
	  return list;
}
 
开发者ID:JackChan1999,项目名称:TakeoutService,代码行数:13,代码来源:CommonUtil.java


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