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