本文整理匯總了Java中net.sf.json.JSONObject.fromObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.fromObject方法的具體用法?Java JSONObject.fromObject怎麽用?Java JSONObject.fromObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.sf.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.fromObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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);
}
示例2: getSelfInfo
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public final User getSelfInfo(){
JSONObject data=JSONObject.fromObject(utils.get(URL.URL_GET_SELF_INFO,new HttpHeader[]{URL.URL_REFERER,credential.getCookie()}).getContent("UTF-8"));
JSONObject info=data.getJSONObject("result");
//獲取生日
JSONObject birthday=info.getJSONObject("birthday");
//構造一個用戶
User user=new User(info.getLong("account"));
//設置昵稱為結果內的nick值
user.setNickName(info.getString("nick"));
//設置性別為結果內的gender值,有male,female,unknown三種屬性
user.setGender(info.getString("gender"));
//設置生日
user.setBirthday(birthday.getInt("year")+"-"+birthday.getInt("month")+"-"+birthday.getInt("day"));
//設置vip級別
user.setVipLevel(info.getInt("vip_info"));
//獲取自己的簽名
user.setPersonal(info.getString("lnick"));
//設置自己的頭像
user.setLogo(logoUtil.getUserLogoByUin(info.getLong("account")));
return user;
}
示例3: 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;
}
示例4: toFifth
import net.sf.json.JSONObject; //導入方法依賴的package包/類
@Action(value = "toFifth", results = { @Result(name = "stepFifthUI", location = ViewLocation.View_ROOT
+ "orderstep4.jsp") })
public String toFifth() throws Exception{
//未支付押金訂單生成
Mrcodeorder order = null;
if((order=createOrder())!=null){
for(Password p : order.getPasswords()){
String msg = "【碼團網】"+p.getContactors().getName()+"您好!您已下單成功,日期:"+p.getEstimatedTime().toString().substring(0,10)+
",房間:"+p.getRoom().getRoomNumber()+"。酒店正為您辦理入住手續,至酒店確認本人身份後,憑房間密碼"+p.getPassword()+"即可入住。";
System.out.println("message:"+msg);
JSONObject o = JSONObject.fromObject(MessageSend.sendSms(msg, p.getContactors().getPhoneNumber()));
System.out.println("result:"+o);
}
request.setAttribute("msg", "已完成房間入住手續,請至酒店前台核對身份證,並支付押金,即可入住,謝謝!");
}
return "stepFifthUI";
}
示例5: getDiscussList
import net.sf.json.JSONObject; //導入方法依賴的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;
}
示例6: 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;
}
示例7: attrs
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public String attrs() throws Exception {
HttpServletRequest request=Struts2Utils.getRequest();
HttpServletResponse response=Struts2Utils.getResponse();
try{
SurveyDirectory survey=surveyDirectoryManager.getSurvey(id);
JsonConfig cfg = new JsonConfig();
cfg.setExcludes(new String[]{"handler","hibernateLazyInitializer"});
JSONObject jsonObject=JSONObject.fromObject(survey,cfg);
response.getWriter().write(jsonObject.toString());
}catch(Exception e){
e.printStackTrace();
}
return null;
}
示例8: getBorrowInfoById
import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
* 根據借閱id查詢該借閱信息
* @return
*/
public String getBorrowInfoById(){
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/json;charset=utf-8");
BorrowInfo info = new BorrowInfo();
info.setBorrowId(borrowId);
BorrowInfo newInfo = borrowService.getBorrowInfoById(info);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
public boolean apply(Object obj, String name, Object value) {
if(obj instanceof Authorization||name.equals("authorization") || obj instanceof Set || name.equals("borrowInfos")){
return true;
}else{
return false;
}
}
});
JSONObject jsonObject = JSONObject.fromObject(newInfo,jsonConfig);
try {
response.getWriter().print(jsonObject);
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
return null;
}
示例9: main
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public static void main(String[] args) {
DefaultSetting.setDefaultNetwork();
if(args.length==0){
OutputMessage.error("please enter parameter");
return;
}
Map<String, String> params = parseParamsToMap(args);
if(params==null){
return;
}
// set host and port
DefaultSetting.setHostAndPort(params.get("host"), params.get("port"), null);
// get multisig public key
String multisigPublicKey = KeyConvertor.getPublicKeyFromAddress(params.get("multisigAddress"));
if(StringUtils.isEmpty(multisigPublicKey)){
OutputMessage.error("unable to find multisig public Key from multisig address");
return;
}
// send transaction
String innerTransactionHash = params.get("innerTransactionHash");
String cosignatoryPublicKey = params.get("cosignatoryPublicKey");
String cosignatoryPrivateKey = params.get("cosignatoryPrivateKey");
String multisigAddress = params.get("multisigAddress");
String fee = params.get("fee");
CosignMultisigTransaction tx = new CosignMultisigTransaction(cosignatoryPublicKey, cosignatoryPrivateKey, multisigAddress, multisigPublicKey, innerTransactionHash);
JSONObject result = JSONObject.fromObject(tx.send_v2(fee));
if(result.containsKey("message") && "SUCCESS".equals(result.getString("message"))){
String transactionHash = result.getJSONObject("transactionHash").getString("data");
OutputMessage.initCosignTransactionMessage("success", transactionHash);
} else {
OutputMessage.error(result.getString("message"));
}
}
示例10: 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;
}
示例11: getBook
import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
* 得到指定圖書編號的圖書信息
* ajax請求該方法
* 返回該圖書信息的json對象
* @return
*/
public String getBook(){
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/json;charset=utf-8");
Book book = new Book();
book.setBookId(bookId);
Book newBook = bookService.getBookById(book);//得到圖書
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setJsonPropertyFilter(new PropertyFilter() {
public boolean apply(Object obj, String name, Object value) {
if(obj instanceof Authorization||name.equals("authorization")){
return true;
}else{
return false;
}
}
});
JSONObject jsonObject = JSONObject.fromObject(newBook,jsonConfig);
try {
response.getWriter().print(jsonObject);
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
return null;
}
示例12: updateDomainServers
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public void updateDomainServers(Site site) {
SimpleSite ss = new SimpleSite(site);
JSONObject json = JSONObject.fromObject(ss);
//先更新當前應用內存中的
com.xnx3.domain.G.putDomain(ss.getDomain(), ss);
if(ss.getBindDomain() != null && ss.getBindDomain().length() > 1){
com.xnx3.domain.G.putBindDomain(ss.getBindDomain(), ss);
}
//若用戶使用了分布式,那麽就要用MNS同步域名改動
if(com.xnx3.domain.G.domainMNSUtil != null){
com.xnx3.domain.G.domainMNSUtil.putMessage(com.xnx3.domain.G.mnsDomain_queueName, json.toString());
}
}
示例13: monitorCosignUnconfirmed
import net.sf.json.JSONObject; //導入方法依賴的package包/類
/**
* monitor multisig unconfirmed (cosign)
* @param result
* @return
*/
private void monitorCosignUnconfirmed(String result){
JSONObject json = null;
try {
json = JSONObject.fromObject(result);
} catch (Exception ex) {
return;
}
if(!json.containsKey("otherHash")
|| !json.containsKey("otherAccount")
|| json.getLong("type")!=Constants.TX_TYPE_COSIGN_MULTISIG){
return;
}
long timeStamp = json.getLong("timeStamp");
String innerTransactionHash = json.getJSONObject("otherHash").getString("data");
String otherAccount = json.getString("otherAccount");
String cosignAddress = KeyConvertor.getAddressFromPublicKey(json.getString("signer"));
if(!otherAccount.equals(this.address)){
return;
}
if(!outCosignedMap.containsKey(innerTransactionHash)){
return;
}
JSONObject outJSON = outCosignedMap.get(innerTransactionHash);
JSONObject outCosignAccount = new JSONObject();
JSONArray outCosignAccountArray = outJSON.getJSONArray("cosignAccount");
outCosignAccount.put("address", cosignAddress);
outCosignAccount.put("date", DateUtils.nemToRealDateStr(timeStamp));
outCosignAccountArray.add(outCosignAccount);
if(outCosignAccountArray.size()>=outJSON.getInt("minCosignatories")){
outCosignedMap.remove(innerTransactionHash);
return;
}
JSONArray outUnsignedAccountArray = outJSON.getJSONArray("unsignedAccount");
int removeIndex = -1;
for(int i=0;i<outUnsignedAccountArray.size();i++){
if(outUnsignedAccountArray.getJSONObject(i).getString("address").equals(cosignAddress)){
removeIndex = i;
break;
}
}
if(removeIndex!=-1) {
outUnsignedAccountArray.remove(removeIndex);
}
outJSON.put("cosignAccount", outCosignAccountArray);
outJSON.put("unsignedAccount", outUnsignedAccountArray);
outCosignedMap.put(innerTransactionHash, outJSON);
System.out.println(outJSON.toString());
}
示例14: getStockDataByStockCode
import net.sf.json.JSONObject; //導入方法依賴的package包/類
public static Map<String, Object> getStockDataByStockCode(String stockCode, String market) {
Object record = RedisLookUp.get("kg_stock:" + stockCode + "_" + market);
// System.out.println("kg_stock:" + stockCode + "_" + market);
Map<String, Object> stockDataMap = new HashMap<String, Object>();
stockDataMap.put("stockCode", stockCode);
if(record == null) {
stockDataMap.put("market", 0); //所屬市場
// stockDataMap.put("stkcode", "0"); //證券代碼
stockDataMap.put("stkname", "-"); //證券名稱
stockDataMap.put("cirqty", 0L); //流通股本
stockDataMap.put("preCloseprice", 0); //前天收盤價
stockDataMap.put("maxRiseValue", 0); //今日漲停價
stockDataMap.put("maxDownValue", 0); //今日跌停價
stockDataMap.put("stFlag", 0); //ST標識
stockDataMap.put("stFlag2", 0); //*ST標識
stockDataMap.put("ptFlag", 0); //PT標識
stockDataMap.put("fxFlag", 0); //高風險警示標識
stockDataMap.put("delistingFlag", 0); //退市整理期標識
stockDataMap.put("", 0); //複牌標識
stockDataMap.put("quitFlag", 0); //已退市標識
stockDataMap.put("delistingStartTime", "0"); //退市整理期開始日期
stockDataMap.put("delistingEndTime", "0"); //退市整理期結束日期
} else {
JSONObject recordJSON = JSONObject.fromObject(record);
// String[] recordFields = record.toString().split(",");
stockDataMap.put("market", recordJSON.getInt("market")); //所屬市場
// stockDataMap.put("stkcode", recordFields[1]); //證券代碼
stockDataMap.put("stkname", recordJSON.getString("stkname")); //證券名稱
stockDataMap.put("cirqty", recordJSON.getLong("cirqty")); //流通股本
stockDataMap.put("preCloseprice", recordJSON.getDouble("closeprice")); //前天收盤價
stockDataMap.put("maxRiseValue", recordJSON.getDouble("maxRiseValue")); //今日漲停價
stockDataMap.put("maxDownValue", recordJSON.getDouble("maxDownValue")); //今日跌停價
stockDataMap.put("stFlag", recordJSON.getInt("stFlag")); //ST標識
stockDataMap.put("stFlag2", recordJSON.getInt("stFlag2")); //*ST標識
stockDataMap.put("ptFlag", recordJSON.getInt("ptFlag")); //PT標識
stockDataMap.put("fxFlag", recordJSON.getInt("fxFlag")); //高風險警示標識
stockDataMap.put("delistingFlag", recordJSON.getInt("delistingFlag")); //退市整理期標識
stockDataMap.put("resumeFlag", recordJSON.getInt("resumeFlag")); //複牌標識
stockDataMap.put("quitFlag", recordJSON.getInt("quitFlag")); //已退市標識
stockDataMap.put("delistingStartTime", recordJSON.getString("delistingStartTime")); //退市整理期開始日期
stockDataMap.put("delistingEndTime", recordJSON.getString("delistingEndTime")); //退市整理期結束日期
}
System.out.println(JSONObject.fromObject(stockDataMap).toString());
return stockDataMap;
}
示例15: execute
import net.sf.json.JSONObject; //導入方法依賴的package包/類
@Override
public void execute(Tuple input) {
if(eplManager.isUpdate()) {
try {
eplManager.getCountDownLatch().await();
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
String record = input.getValue(0).toString();
json = JSONObject.fromObject(record);
if (json.containsKey("funcid") && TextUtils.isNumeric(json.getString("funcid").trim())
&& eplManager.getSchema(Integer.parseInt(json.getString("funcid"))) != null
&& eplManager.getSchema(Integer.parseInt(json.getString("funcid"))).size() > 0
&& eplManager.getGroupKeys(Integer.parseInt(json.getString("funcid"))) != null
&& eplManager.getGroupKeys(Integer.parseInt(json.getString("funcid"))).size() > 0) {
Map<String, Object> schemaMap = null;
if(json.containsKey("rc_msg_para")) {
String rcMsgPara = json.getString("rc_msg_para");
schemaMap = JSONObject.fromObject(rcMsgPara);
for(Object fieldName : json.keySet()) {
if(!schemaMap.containsKey(fieldName) && !"rc_msg_para".equals(fieldName.toString().trim())) {
schemaMap.put(fieldName.toString(), json.get(fieldName));
}
}
} else {
schemaMap = json;
}
int funcid = Integer.parseInt(json.getString("funcid"));
// if(funcid == 100000 && !schemaMap.containsKey("market")){
// collector.ack(input);
// return;
// }
//過濾掉非股票交易
if(schemaMap.containsKey("market") && (schemaMap.containsKey("stkcode") || schemaMap.containsKey("zqdm"))) {
String market = schemaMap.get("market").toString();
String stkcode = schemaMap.get("stkcode") != null ? schemaMap.get("stkcode").toString() : schemaMap.get("zqdm").toString();
if((!"1".equals(market) && !"0".equals(market))
||("1".equals(market) && !stkcode.startsWith("60"))
|| ("0".equals(market) && !stkcode.startsWith("00") && !stkcode.startsWith("30"))) {
collector.ack(input);
return;
}
}
if(!schemaMap.containsKey("timestamp")) {
schemaMap.put("timestamp", System.currentTimeMillis());
} else {
schemaMap.put("timestamp", Long.parseLong(schemaMap.get("timestamp").toString()));
}
List<Schema> schemas = eplManager.getSchema(funcid);
StringBuilder keyStr = null;
for(Schema schema : schemas) {
String[] keys = schema.getFieldGroupKey().split("\\|");
keyStr = new StringBuilder();
for (String key : keys) {
keyStr.append(schemaMap.get(key));
}
schemaMap.put("tableName", schema.getExtSchemaName());
System.out.println("tableName : " + schema.getExtSchemaName() + ", key: " + keyStr.toString() + ", Values : " + JSONObject.fromObject(schemaMap).toString());
collector.emit(new Values(keyStr.toString(), schemaMap));
}
keyStr = null;
}
collector.ack(input);
}