本文整理汇总了Java中net.sf.json.JSONObject.toBean方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.toBean方法的具体用法?Java JSONObject.toBean怎么用?Java JSONObject.toBean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.toBean方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
示例4: 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);
}
示例5: 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;
}
示例6: getSelectedAttachments
import net.sf.json.JSONObject; //导入方法依赖的package包/类
public List<AttachmentId> getSelectedAttachments()
{
ArrayList<AttachmentId> attachments = new ArrayList<AttachmentId>();
if( selected != null )
{
for( String selectId : selected )
{
JSONObject selObj = JSONObject.fromObject(selectId);
AttachmentId attachId = (AttachmentId) JSONObject.toBean(selObj, AttachmentId.class);
attachments.add(attachId);
}
}
return attachments;
}
示例7: getBeanFromAttribute
import net.sf.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <T> T getBeanFromAttribute(MimeEntry entry, String key, Class<T> entryType)
{
Map<String, String> attr = entry.getAttributes();
String enabledJson = attr.get(key);
if( !Check.isEmpty(enabledJson) )
{
return (T) JSONObject.toBean(JSONObject.fromObject(enabledJson), entryType);
}
return null;
}
示例8: 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;
}
示例9: onSend
import net.sf.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("finally")
public String onSend(String phone, String content) {
String messagecode = "";
String sql ="select * from pub_sms_platform where id=3";
SmsPlatform platform = (SmsPlatform) this.daoSupport.queryForObject(sql, SmsPlatform.class);
String config=platform.getConfig();
JSONObject jsonObject = JSONObject.fromObject(config);
Map configMap = (Map)jsonObject.toBean(jsonObject, Map.class);
String url=configMap.get("url").toString();
String uid=configMap.get("uid").toString();
String pwd=configMap.get("pwd").toString();
// pwd=StringUtil.md5(uid+pwd);//加密
// pwd="4b3d06d1fce032d72294c93e59ef8733";
// 创建StringBuffer对象用来操作字符串
StringBuffer sb = new StringBuffer(url);
// 向StringBuffer追加用户名
sb.append("?action=sendOnce&uid=").append(uid);
// 向StringBuffer追加密码(密码采用MD5 32位 小写)
sb.append("&pwd=").append(pwd);
// 向StringBuffer追加手机号码
sb.append("&mobile=").append(phone);
// 向StringBuffer追加消息内容转URL标准码
sb.append("&content=").append(URLEncoder.encode(content));
sb.append("&encode=utf8");
System.out.println(sb.toString());
try {
// 创建url对象
URL url2 = new URL(sb.toString());
// 打开url连接
HttpURLConnection connection = (HttpURLConnection) url2.openConnection();
// 设置url请求方式 ‘get’ 或者 ‘post’
connection.setRequestMethod("POST");
// 发送
BufferedReader in = new BufferedReader(new InputStreamReader(url2.openStream()));
// 返回发送结果
String result = in.readLine().toString();
System.out.println("网关信息:"+decodeUnicode(result));
// 将String转换为XML文档
Document doc=DocumentHelper.parseText(result);
messagecode=parseDOM4J(doc);
} catch (Exception e) {
e.printStackTrace();
} finally {
String message=getResponse(messagecode);
// Map<String,String> smsMap = new HashMap<String,String>();
// JSONObject jsonObj = JSONObject.fromObject(message);
// smsMap = (Map)jsonObject.toBean(jsonObj, Map.class);
// smsMap.put("messagecode",result);
// smsMap.put("message", message);
AppConfigParse appconfig=new AppConfigParse();
System.out.println(appconfig.getAppId("similar_sms"));
if("yes".equals(appconfig.getAppId("similar_sms"))){
this.mockSend(message);
}
return str2json(messagecode);
}
}
示例10: toObject
import net.sf.json.JSONObject; //导入方法依赖的package包/类
/**
* json to object
* @param jsonStr
* @param objClass
* @return
*/
public static Object toObject(final String jsonStr,Class<?> objClass){
JSONObject jsObject = JSONObject.fromObject(jsonStr);
return JSONObject.toBean(jsObject, objClass);
}