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


Java JSONObject类代码示例

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


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

示例1: doPost

import net.sf.json.JSONObject; //导入依赖的package包/类
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	JSONObject voo = new JSONObject();
	voo.put("aircraft", "A320");
	voo.put("maxPax", 200);
	
	JSONObject piloto = new JSONObject();
	piloto.put("firstName", "John");
	piloto.put("lastName", "Doe");
	voo.put("pilot", piloto);
	
	voo.accumulate("passenger", "George");
	voo.accumulate("passenger", "Thomas");
	
	// enviar os dados no formato JSON
	PrintWriter out = response.getWriter();
	response.setContentType("text/plain");
	out.println(voo.toString(2));
}
 
开发者ID:thiagola92,项目名称:PUC-INF1407,代码行数:19,代码来源:BuscaVoo.java

示例2: refreshOauth2Token

import net.sf.json.JSONObject; //导入依赖的package包/类
/**
 * 刷新网页授权凭证
 * @param appId
 * @param appSecret
 * @param code
 * @return
 */
public Oauth2Token refreshOauth2Token(String appId,String refreshToken){
	logger.info("refreshOauth2Token appId : {} , refreshToken : {} ", appId, refreshToken);
	Oauth2Token oauth2Token = null;
	String requestUrl = refresh_token_url.replace("APPID", appId).replace("REFRESH_TOKEN", refreshToken);
	JSONObject jsonObject = CommonUtil.httpsRequest(requestUrl, "GET", null);
	if(null != jsonObject){
		try{
			oauth2Token = new Oauth2Token();
			oauth2Token.setAccessToken(jsonObject.getString("access_token"));
			oauth2Token.setExpiresIn(jsonObject.getInt("expires_in"));
			oauth2Token.setRefreshToken(jsonObject.getString("refresh_token"));
			oauth2Token.setOpenId(jsonObject.getString("openid"));
			oauth2Token.setScope(jsonObject.getString("scope"));
		}catch(Exception e){
			oauth2Token = null;
			int errCode = jsonObject.getInt("errcode");
			String errMsg = jsonObject.getString("errmsg");
			logger.error("刷新网页授权凭证失败 errCode : {} , errmsg : {} ", errCode,errMsg);
		}
	}
	logger.info("refreshOauth2Token => 返回 :" + com.alibaba.fastjson.JSONObject.toJSONString(oauth2Token)); 
	return oauth2Token;
}
 
开发者ID:tojaoomy,项目名称:private-WeChat,代码行数:31,代码来源:AuthorizationService.java

示例3: deserialize

import net.sf.json.JSONObject; //导入依赖的package包/类
@Override
public List<Object> deserialize(ByteBuffer ser) {
    String jsonStr = null;
    if (ser.hasArray()) {
        int base = ser.arrayOffset();
        jsonStr = new String(ser.array(), base + ser.position(), ser.remaining());
    } else {
        jsonStr = new String(Utils.toByteArray(ser), UTF8_CHARSET);
    }
    JSONObject jsonObject = JSONObject.fromObject(jsonStr);
    Values values = new Values();
    for (String outputField : outputFields) {
        if("jsonBody".equals(outputField)) {
            values.add(jsonStr);
        } else {
            if(!jsonObject.containsKey(outputField)) {
                JSONObject rcMsgpara = JSONObject.fromObject(jsonObject.get("rc_msg_para"));
                values.add(rcMsgpara.get(outputField));
            } else {
                values.add(jsonObject.get(outputField));
            }
        }
    }
    return values;
}
 
开发者ID:JiuzhouSec,项目名称:nightwatch,代码行数:26,代码来源:JSONScheme.java

示例4: map2jsonConverter

import net.sf.json.JSONObject; //导入依赖的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: getGroupList

import net.sf.json.JSONObject; //导入依赖的package包/类
public ArrayList<Group> getGroupList(){
	ArrayList<Group> groupsList=new ArrayList<Group>();
	JSONObject r=new JSONObject();
	r.put("vfwebqq",credential.getVfWebQQ());
	r.put("hash",credential.getHash());
	//构造一个请求表单,用于获取群列表
	
	//访问获取群信息的链接,并将结果解析为json
	JSONObject result=JSONObject.fromObject(utils.post(URL.URL_GET_GROUP_LIST,new PostParameter[]{new PostParameter("r",r.toString())},new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8")).getJSONObject("result");
	//从结果取出群列表
	JSONArray groups=result.getJSONArray("gnamelist");
	//构造群对象
	for(int i=0;i<groups.size();i++){
		JSONObject tempInfo=JSONObject.fromObject(groups.get(i));
		//构造一个群对象,gid为群id,gcode用于获取成员,credential用于获取成员列表
		Group tempGroup=new Group(tempInfo.getLong("gid"),tempInfo.getLong("code"),credential);
		//设置群的名称
		tempGroup.setName(tempInfo.getString("name"));
		groupsList.add(tempGroup);
	}
	return groupsList;
}
 
开发者ID:KittenDev,项目名称:WebQQAPI,代码行数:23,代码来源:Account.java

示例6: getDiscussUsers

import net.sf.json.JSONObject; //导入依赖的package包/类
public ArrayList<User> getDiscussUsers(){
	ArrayList<User> users=new ArrayList<User>();
	//用这个讨论组的did,以及vfwebqq合成一个完整的URL,并且将结果解析为json对象
	String url=URL.URL_GET_DISCUSS_INFO.replace("[var]",Long.toString(discussID)).replace("[var1]",credential.getVfWebQQ()).replace("[var2]",credential.getPsessionID());
	String info=utils.get(url,new HttpHeader[]{URL.URL_MESSAGE_REFERER,credential.getCookie()}).getContent("UTF-8");
	JSONObject result=JSONObject.fromObject(info).getJSONObject("result");
	//获取用户信息
	JSONArray usersInfo=result.getJSONArray("mem_info");
	//获取在线状态
	JSONArray usersStatus=result.getJSONArray("mem_status");
	//设置昵称,状态以及uin
	int tempIndex=0;
	for(int i=0;i<usersInfo.size();i++){
		JSONObject tempUserInfo=JSONObject.fromObject(usersInfo.get(i));
		User tempUser=new User(tempUserInfo.getLong("uin"));
		tempUser.setNickName(tempUserInfo.getString("nick"));
		if(tempIndex<usersStatus.size()&&tempUser.getUID()==JSONObject.fromObject(usersStatus.get(tempIndex)).getLong("uin")){
			tempUser.setOnlineStatus(true);
			tempIndex++;
	}
		users.add(tempUser);
	}
	return users;
	
}
 
开发者ID:KittenDev,项目名称:WebQQAPI,代码行数:26,代码来源:Discuss.java

示例7: commonGridQuery

import net.sf.json.JSONObject; //导入依赖的package包/类
/**
 * commonGridQuery 通用grid数据查询
 * key:查询条件书写规范: "UUserMapper_gridUsers"(Dao接口名_方法名)
 *
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/comGridQuery", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> commonGridQuery(HttpServletRequest request, HttpServletResponse response) throws Exception {

  HashMap<String, String> params = HttpReqsUtil.getRequestVals(request);
  log.debug("grid通用查询参数:==>" + String.valueOf(params));

  String data = params.get("data");
  JSONObject obj = JSONObject.fromObject(data);//查询条件
  HashMap<String, String> paramsMap = (HashMap<String, String>) JSONObject.toBean(JSONObject.fromObject(obj), HashMap.class);

  Map<String, Object> resultMap = null;

  /*分页*/
  int pageIndex = Integer.parseInt(request.getParameter("pageIndex"));
  int pageSize = Integer.parseInt(request.getParameter("pageSize"));
  /*字段排序*/
  String sortField = request.getParameter("sortField");
  String sortOrder = request.getParameter("sortOrder");

  resultMap = selectService.queryGridKey(pageIndex,pageSize,sortField,sortOrder,paramsMap);

  return resultMap;
}
 
开发者ID:MiniPa,项目名称:cjs_ssms,代码行数:34,代码来源:SelectController.java

示例8: main

import net.sf.json.JSONObject; //导入依赖的package包/类
@SuppressWarnings("static-access")
public static void main(String[] args) throws Exception{
   	/*for (int i = 0; i < 100; i++) {
   		System.out.println(MessageSend.getVerificationCode());
	}*/
	
   	JSONObject result = JSONObject.fromObject(DataUtils.getMap("res","123465461"));
   	System.out.println(result.get("res"));
   	/*try {
		String msg = MessageSend.sendDynamicVerification("546824", "15959277729");
		System.out.println(msg);
   	} catch (IOException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}*/
   }
 
开发者ID:liuxuanhai,项目名称:WeiXing_xmu-2016-MrCode,代码行数:17,代码来源:MessageSend.java

示例9: usersGridQuery

import net.sf.json.JSONObject; //导入依赖的package包/类
/**
 * users gird表查询
 *
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
@RequestMapping(value = "/userGridQuery", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> usersGridQuery(HttpServletRequest request, HttpServletResponse response) throws Exception {

  HashMap<String, String> params = HttpReqsUtil.getRequestVals(request);
  log.debug("grid通用查询参数:==>" + String.valueOf(params));

  String data = params.get("data");
  JSONObject obj = JSONObject.fromObject(data);//查询条件
  HashMap<String, String> paramsMap = (HashMap<String, String>) JSONObject.toBean(JSONObject.fromObject(obj), HashMap.class);

  Map<String, Object> resultMap = null;

  /*分页*/
  int pageIndex = Integer.parseInt(request.getParameter("pageIndex"));
  int pageSize = Integer.parseInt(request.getParameter("pageSize"));
  /*字段排序*/
  String sortField = request.getParameter("sortField");
  String sortOrder = request.getParameter("sortOrder");

  return  getGrids(pageIndex, pageSize, paramsMap);
}
 
开发者ID:MiniPa,项目名称:cjs_ssms,代码行数:31,代码来源:SelectController.java

示例10: getOauth2Token

import net.sf.json.JSONObject; //导入依赖的package包/类
/**
 * 获取网页授权凭证
 * @param appId
 * @param appSecret
 * @param code
 * @return
 */
public Oauth2Token getOauth2Token(String appId,String appSecret,String code){
	Oauth2Token oauth2Token = null;
	String requestUrl = access_token_url.replace("APPID", appId).replace("SECRET", appSecret).replace("CODE", code);
	logger.info("getOauth2Token => ###### requestUrl : " + requestUrl);
	JSONObject jsonObject = CommonUtil.httpsRequest(requestUrl, "GET", null);
	if(null != jsonObject){
		try{
			oauth2Token = new Oauth2Token();
			oauth2Token.setAccessToken(jsonObject.getString("access_token"));
			oauth2Token.setExpiresIn(jsonObject.getInt("expires_in"));
			oauth2Token.setRefreshToken(jsonObject.getString("refresh_token"));
			oauth2Token.setOpenId(jsonObject.getString("openid"));
			oauth2Token.setScope(jsonObject.getString("scope"));
		}catch(Exception e){
			oauth2Token = null;
			int errCode = jsonObject.getInt("errcode");
			String errMsg = jsonObject.getString("errmsg");
			logger.error("获取网页授权凭证失败 errCode : {} , errmsg : {} ", errCode,errMsg);
		}
	}
	logger.info("getOauth2Token => 返回 :" + com.alibaba.fastjson.JSONObject.toJSONString(oauth2Token)); 
	return oauth2Token;
}
 
开发者ID:tojaoomy,项目名称:private-WeChat,代码行数:31,代码来源:AuthorizationService.java

示例11: sendVerification

import net.sf.json.JSONObject; //导入依赖的package包/类
/**
 * 发送短信验证码
 * 
 * @return
 */
@Action(value = "sendVerification")
public void sendVerification() throws Exception {
	String phone = getParameter("phone");
	System.out.println("CustomerAction.sendVerification()");
	// 1.生成验证码
	String verificationCode = MessageSend.getVerificationCode();
	try {
		JSONObject result = JSONObject
				.fromObject(MessageSend.sendDynamicVerification(
						verificationCode, phone));
		if ("OK".equals(result.get("msg"))) {
			session.clear();
			session.put("verificationCode", verificationCode);
			writeStringToResponse("【ok】");
		}
	} catch (Exception e) {
		log.error("发送验证码失败!");
		e.printStackTrace();
	}

}
 
开发者ID:liuxuanhai,项目名称:WeiXing_xmu-2016-MrCode,代码行数:27,代码来源:LoginPhoneAction.java

示例12: getDTO

import net.sf.json.JSONObject; //导入依赖的package包/类
/**
 * 从一个JSON 对象字符格式中得到一个java对象,形如: {"id" : idValue, "name" : nameValue,
 * "aBean" : {"aBeanId" : aBeanIdValue, ...}}
 * 
 * @param object
 * @param clazz
 * @return
 */
public static Object getDTO(String jsonString, Class<?> clazz) {
	JSONObject jsonObject = null;
	try {
		setDataFormat2JAVA();
		jsonObject = JSONObject.fromObject(jsonString);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return JSONObject.toBean(jsonObject, clazz);
}
 
开发者ID:jiangzongyao,项目名称:kettle_support_kettle8.0,代码行数:19,代码来源:JSONUtil.java

示例13: findMosaicFeeInformationByNIS

import net.sf.json.JSONObject; //导入依赖的package包/类
public static MosaicFeeInformation findMosaicFeeInformationByNIS(MosaicId mosaicId){
	String queryResult = HttpClientUtils.get(Constants.URL_NAMESPACE_MOSAIC_DEFINITION_PAGE + "?namespace=" + mosaicId.getNamespaceId().toString());
	JSONObject json = JSONObject.fromObject(queryResult);
	if(json==null || !json.containsKey("data") || json.getJSONArray("data").size()==0){
		return null;
	}
	JSONArray array = json.getJSONArray("data");
	for(int i=0;i<array.size();i++){
		JSONObject item = array.getJSONObject(i);
		JSONObject mosaic = item.getJSONObject("mosaic");
		JSONObject id = mosaic.getJSONObject("id");
		if(mosaicId.getName().equals(id.getString("name"))){
			JSONArray properties = mosaic.getJSONArray("properties");
			String initialSupply = "";
			String divisibility = "";
			for(int j=0;j<properties.size();j++){
				JSONObject property = properties.getJSONObject(j);
				if("initialSupply".equals(property.getString("name"))){
					initialSupply = property.getString("value");
				} else if("divisibility".equals(property.getString("name"))){
					divisibility = property.getString("value");
				}
			}
			if(!"".equals(initialSupply) && !"".equals(divisibility)){
				return new MosaicFeeInformation(Supply.fromValue(Long.valueOf(initialSupply)), Integer.valueOf(divisibility));
			}
		}
	}
	return null;
}
 
开发者ID:NEMChina,项目名称:nem-apps,代码行数:31,代码来源:NISQuery.java

示例14: getDTOArray

import net.sf.json.JSONObject; //导入依赖的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

示例15: jsonToBean

import net.sf.json.JSONObject; //导入依赖的package包/类
/**
 * Converts the input JSON structure into an instance of the beanClassName.
 * If the beanClassName is null, then an instance of org.apache.commons.beanutils.DynaBean will be returned.
 * 
 * @param input
 *            input as a JSON structure.
 * @param beanClassName
 *            the name of the bean class.
 * @return the input JSON structure as an instance of the beanClassName.
 * @throws ClassNotFoundException if the beanClassName is invalid.
 */
public static Object jsonToBean(String input, String beanClassName) throws ClassNotFoundException {
    if (log.isDebugEnabled())
        log.debug("Converting JSON '" + input + "' into an instance of " + beanClassName);
    registerCustomMorphers();
    Class beanClass = beanClassName != null ? Class.forName(beanClassName) : null;
    JSONObject jsonObject = JSONObject.fromObject(input);
    Object bean = JSONObject.toBean(jsonObject, createJsonConfig(beanClass));
    if (log.isDebugEnabled())
        log.debug("Converted to: " + bean);
    return bean;
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:23,代码来源:ExcelExportService.java


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