本文整理匯總了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);
}