當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONObject類代碼示例

本文整理匯總了Java中com.alibaba.fastjson.JSONObject的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject類的具體用法?Java JSONObject怎麽用?Java JSONObject使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JSONObject類屬於com.alibaba.fastjson包,在下文中一共展示了JSONObject類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: selectPayChannel

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
@RequestMapping(value = "/pay_channel/select")
public String selectPayChannel(@RequestParam String jsonParam) {
    // TODO 參數校驗
    _log.info("selectPayChannel << {}", jsonParam);
    JSONObject retObj = new JSONObject();
    retObj.put("code", "0000");
    if(StringUtils.isBlank(jsonParam)) {
        retObj.put("code", "0001"); // 參數錯誤
        retObj.put("msg", "缺少參數");
        return retObj.toJSONString();
    }
    JSONObject paramObj = JSON.parseObject(new String(MyBase64.decode(jsonParam)));
    String channelId = paramObj.getString("channelId");
    String mchId = paramObj.getString("mchId");
    PayChannel payChannel = payChannelService.selectPayChannel(channelId, mchId);
    if(payChannel == null) {
        retObj.put("code", "0002");
        retObj.put("msg", "數據對象不存在");
        return retObj.toJSONString();
    }
    retObj.put("result", JSON.toJSON(payChannel));
    _log.info("selectPayChannel >> {}", retObj);
    return retObj.toJSONString();
}
 
開發者ID:ywtnhm,項目名稱:pay-xxpay-master,代碼行數:25,代碼來源:PayChannelServiceController.java

示例2: createConfig

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
public static LogcenterConfig createConfig(JSONObject jsonInput) throws LogConsumerException {
    String productLine = String.valueOf(jsonInput.get("productLine"));
    String appName = String.valueOf(jsonInput.get("appName"));
    QueryBuilder qb = QueryBuilders.queryStringQuery("productLine:'" + productLine + "' AND appName:'" + appName + "'");
    SearchResponse response = ElasticsearchClient.getClient()
            .prepareSearch(Constants.METADATA_INDEX)
            .setTypes(Constants.METADATA_TYPE)
            .setQuery(qb)
            .get();
    JSONObject jsonObject = JSON.parseObject(response.toString());
    JSONArray hitArray = (JSONArray) jsonObject.getJSONObject("hits").get("hits");
    if (hitArray.size() == 0) {
        throw new LogConsumerException("index does not exist,please check the configuration of the .logcenter index");
    }
    JSONObject document = (JSONObject) hitArray.get(0);
    String jsonStr = document.get("_source").toString();

    return JSONObject.parseObject(jsonStr, LogcenterConfig.class);
}
 
開發者ID:geeker-lait,項目名稱:tasfe-framework,代碼行數:20,代碼來源:LogConfigFactory.java

示例3: getUserInfo

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
public static String getUserInfo(String code, int agentid) {
		String urlStr = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token="+WeiXinCompanyUtils.getToken()+
//				"&code="+code+"&agentid="+CommonUtils.WX_QY_AGENT_TEST;
				"&code="+code+"&agentid="+agentid;
		try {
			URL url = new URL(urlStr);
			HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();

			conn.setDoInput(true);

			BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
			String s = null;
			StringBuilder sb = new StringBuilder();
			while ((s=reader.readLine()) != null) {
				sb.append(s);
			}
			JSONObject jsonObject = JSON.parseObject(sb.toString());
			if(jsonObject.get("UserId") !=null){
				return jsonObject.get("UserId").toString();
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
 
開發者ID:iBase4J,項目名稱:iBase4J-Common,代碼行數:27,代碼來源:WeiXinCompanyOAuth.java

示例4: lastdp

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
@Override
public List<LastDPValue> lastdp(Collection<Timeline> timelines) throws HttpUnknowStatusException {
	Object timelinesJSON = JSON.toJSON(timelines);
	JSONObject obj = new JSONObject();
	obj.put("queries", timelinesJSON);
	String jsonString = obj.toJSONString();
	HttpResponse httpResponse = httpclient.post(HttpAPI.QUERY_LASTDP, jsonString);
	ResultResponse resultResponse = ResultResponse.simplify(httpResponse, this.httpCompress);
	HttpStatus httpStatus = resultResponse.getHttpStatus();
	switch (httpStatus) {
	case ServerSuccessNoContent:
		return null;
	case ServerSuccess:
		String content = resultResponse.getContent();
		List<LastDPValue> queryResultList = JSON.parseArray(content, LastDPValue.class);
		return queryResultList;
	case ServerNotSupport:
		throw new HttpServerNotSupportException(resultResponse);
	case ServerError:
		throw new HttpServerErrorException(resultResponse);
	default:
		throw new HttpUnknowStatusException(resultResponse);
	}
}
 
開發者ID:aliyun,項目名稱:HiTSDB-Client,代碼行數:25,代碼來源:HiTSDBClient.java

示例5: bulkUpsert

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
public String bulkUpsert(String index,String type,List<Object> jsons){
	try {
		if(client==null){
			init();
		}
		BulkRequestBuilder bulkRequest = client.prepareBulk();
		for (Object json : jsons) {
			JSONObject obj = JSON.parseObject(JSON.toJSONString(json));
			String id = UUIDs.base64UUID();
			if(obj.containsKey("id")){
				id = obj.getString("id");
				obj.remove("id");
				bulkRequest.add(client.prepareUpdate(index, type, id).setDoc(obj.toJSONString(),XContentType.JSON));
			}else{
				bulkRequest.add(client.prepareIndex(index, type, id).setSource(obj.toJSONString(),XContentType.JSON));
			}
		}
		BulkResponse result = bulkRequest.execute().get();
		return result.toString();
	}catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	return null;
}
 
開發者ID:dev-share,項目名稱:database-transform-tool,代碼行數:26,代碼來源:ElasticsearchTransportFactory.java

示例6: viewInput

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
@RequestMapping("/view.html")
public String viewInput(String payOrderId, ModelMap model) {
    PayOrder item = null;
    if(StringUtils.isNotBlank(payOrderId)) {
        item = payOrderService.selectPayOrder(payOrderId);
    }
    if(item == null) {
        item = new PayOrder();
        model.put("item", item);
        return "pay_order/view";
    }
    JSONObject object = (JSONObject) JSON.toJSON(item);
    if(item.getPaySuccTime() != null) object.put("paySuccTime", DateUtil.date2Str(new Date(item.getPaySuccTime())));
    if(item.getLastNotifyTime() != null) object.put("lastNotifyTime", DateUtil.date2Str(new Date(item.getLastNotifyTime())));
    if(item.getExpireTime() != null) object.put("expireTime", DateUtil.date2Str(new Date(item.getExpireTime())));
    if(item.getAmount() != null) object.put("amount", AmountUtil.convertCent2Dollar(item.getAmount()+""));
    model.put("item", object);
    return "pay_order/view";
}
 
開發者ID:ywtnhm,項目名稱:pay-xxpay-master,代碼行數:20,代碼來源:PayOrderController.java

示例7: createPayOrder

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
@Override
public Map createPayOrder(String jsonParam) {
    BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
    Map<String, Object> bizParamMap = baseParam.getBizParamMap();
    if (ObjectValidUtil.isInvalid(bizParamMap)) {
        _log.warn("新增支付訂單失敗, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
    }
    JSONObject payOrderObj = baseParam.isNullValue("payOrder") ? null : JSONObject.parseObject(bizParamMap.get("payOrder").toString());
    if(payOrderObj == null) {
        _log.warn("新增支付訂單失敗, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
    }
    PayOrder payOrder = BeanConvertUtils.map2Bean(payOrderObj, PayOrder.class);
    if(payOrder == null) {
        _log.warn("新增支付訂單失敗, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
        return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
    }
    int result = super.baseCreatePayOrder(payOrder);
    return RpcUtil.createBizResult(baseParam, result);
}
 
開發者ID:ywtnhm,項目名稱:pay-xxpay-master,代碼行數:22,代碼來源:PayOrderServiceImpl.java

示例8: apply

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
@Override
public void apply(ApiRequest request, ApiResponse response, WebSocketSession session) {
    DrawGuessContext ctx = (DrawGuessContext) session.getAttributes().get("ctx");
    JSONObject obj = JSONObject.parseObject(request.getMsg());
    boolean ready = obj.getBooleanValue(STATUS_NAME);
    String id = obj.getString(ID_NAME);
    DrawPlayerInfo info = ((DrawPlayerInfo) session.getAttributes().get("info"));
    if (ctx.status() != DrawGameStatus.READY) {
        return;
    }
    if (ready && info.status() == DrawUserStatus.WAIT) {
        info.setStatus(DrawUserStatus.READY);
        ctx.addPlayer(info);
    } else if (!ready && info.status() == DrawUserStatus.READY) {
        info.setStatus(DrawUserStatus.WAIT);
        ctx.removePlayer(id);
    }
    response.setCode(DrawCode.USER_READY.getCode()).setData(info);
}
 
開發者ID:csdbianhua,項目名稱:telemarket-skittle-alley,代碼行數:20,代碼來源:ReadyHandler.java

示例9: DefaultLogFilterAndRule

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
/**
 * 構造默認的日誌規則
 * 
 * @param filterregex
 *            日誌過濾規則的正則表達式
 * @param separator
 *            日誌字段分隔符
 * @param fields
 *            日誌字段名以及對應在的列號
 * @param fieldNumber
 *            指定對應的列號值為時間戳
 * @param version
 *            規則當前的版本
 */
public DefaultLogFilterAndRule(String filterregex, String separator, JSONObject fields, int fieldNumber,
        int version) {

    this.filterPattern = Pattern.compile(filterregex);

    this.separator = Splitter.on(separator).trimResults();
    this.SpecifiedFields = new Integer[fields.size()];
    this.fieldsName = new String[fields.size()];
    int i = 0;
    for (Entry<String, Object> entry : fields.entrySet()) {
        fieldsName[i] = entry.getKey();
        SpecifiedFields[i++] = (Integer) entry.getValue();
    }
    this.timeStampField = fieldNumber;

    this.version = version;

    @SuppressWarnings("rawtypes")
    List<Map> mainlogs = Lists.newLinkedList();

    setMainlogs(mainlogs);
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:37,代碼來源:DefaultLogFilterAndRule.java

示例10: write

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
@SuppressWarnings("deprecation")
public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType, int features) throws IOException {
	if (object == null) {
		serializer.out.writeNull();
		return;
	}
	
    Date date = (Date) object;
   
    JSONObject json = new JSONObject();
    json.put("date", date.getDate());
    json.put("day", date.getDay());
    json.put("hours", date.getHours());
    json.put("minutes", date.getMinutes());
    json.put("month", date.getMonth());
    json.put("seconds", date.getSeconds());
    json.put("time", date.getTime());
    json.put("timezoneOffset", date.getTimezoneOffset());
    json.put("year", date.getYear());

    serializer.write(json);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:JSONLibDataFormatSerializer.java

示例11: __buildJsApiConfigStr

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
private String __buildJsApiConfigStr(String appId, String jsapiTicket, String url, String timestamp, String noncestr, boolean debug) throws Exception {
    String _signature = "jsapi_ticket=" + jsapiTicket + "&" + "noncestr=" + noncestr + "&" + "timeStamp=" + timestamp + "&" + "url=" + url;
    _signature = DigestUtils.sha1Hex(_signature);
    //
    JSONObject _json = new JSONObject();
    _json.put("debug", debug);
    _json.put("appId", appId);
    _json.put("timestamp", timestamp);
    _json.put("nonceStr", noncestr);
    _json.put("signature", _signature);
    _json.put("jsApiList", new String[]{"chooseWXPay"});
    //
    return _json.toJSONString();
}
 
開發者ID:suninformation,項目名稱:ymate-payment-v2,代碼行數:15,代碼來源:WxPayJsApiController.java

示例12: getOAuthAccessToken

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
public static OAuthAccessToken getOAuthAccessToken(String appId, String appSecret, String code) {
	OAuthAccessToken token = null;
	String tockenUrl = getOAuthTokenUrl(appId, appSecret, code);
	JSONObject jsonObject = httpsRequest(tockenUrl, HttpMethod.GET, null);
	if (null != jsonObject && !jsonObject.containsKey("errcode")) {
		try {
			token = new OAuthAccessToken();
			token.setAccessToken(jsonObject.getString("access_token"));
			token.setExpiresIn(jsonObject.getInteger("expires_in"));
			token.setOpenid(jsonObject.getString("openid"));
			token.setScope(jsonObject.getString("scope"));
		} catch (JSONException e) {
			token = null;//獲取token失敗
		}
	}else if(null != jsonObject){
		token = new OAuthAccessToken();
		token.setErrcode(jsonObject.getInteger("errcode"));
	}
	return token;
}
 
開發者ID:jmdhappy,項目名稱:xxpay-master,代碼行數:21,代碼來源:WxApi.java

示例13: getTimingByJobId

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
/**
* 通過作業ID獲取作業定時信息<br/>
* @author jingma
* @param dbCode 所在資源庫代碼
* @param jobId 作業ID
* @return SATRT控件實體
*/
public static JSONObject getTimingByJobId(int jobId) {
    Integer startId = getStartIdByJobId(KuConst.DS_KETTLE, jobId);
    if(startId==null){
        return null;
    }
    String sql = "select ja.value_num,ja.value_str,ja.code from r_jobentry_attribute ja "
            + "where ja.id_jobentry=?";
    List<JSONObject> records = Db.use(KuConst.DS_KETTLE).find(sql, startId);
    JSONObject result = new JSONObject();
    for(JSONObject record:records){
        if(StringUtil.isNotBlank(record.getString("value_str"))){
            result.put(startTimingMap.get(record.getString("code")), record.getString("value_str"));
        }else{
            result.put(startTimingMap.get(record.getString("code")), record.getInteger("value_num"));
        }
    }
    result.put("is_repeat", StringUtil.whether(result.getString("is_repeat")));
    return result;
}
 
開發者ID:majinju,項目名稱:KettleUtil,代碼行數:27,代碼來源:TimingUtil.java

示例14: call

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
/**
 * 請求服務
 *
 * @param serverId 服務ID
 * @param name     方法名
 * @param data     數據
 * @return 響應數據
 * @throws Exception 加解密以及io錯誤
 */
public String call(String serverId, String name, String data) throws Exception {
    // 加密請求數據
    byte[] in = data.getBytes("utf-8");
    if (in.length > this.length - Constant.RSA_RESERVED_LENGTH) {
        throw new Exception("request data is too big");
    }
    byte[] bytes = RsaUtils.encryptByPublicKey(in, this.publicKey);
    // bytes轉16進製發送
    String resp = HttpUtils.sendGet(String.format("http://%s/server?sessionId=%s&serverId=%s&name=%s&data=%s",
            this.host, this.sessionId, serverId, name, CoderUtils.bytesToHex(bytes)));
    JSONObject obj = JSON.parseObject(resp);
    Integer code = obj.getInteger(Constant.CODE);
    if (code != 0) {
        throw new Exception(String.format("call server fail, fail code: %d", code));
    }
    // 解密響應
    byte[] receive = RsaUtils.decryptByPublicKey(obj.getBytes(Constant.DATA), this.publicKey);
    return new String(receive);
}
 
開發者ID:cwdtom,項目名稱:hermes-java,代碼行數:29,代碼來源:Center.java

示例15: convertJSONObjectToMessage

import com.alibaba.fastjson.JSONObject; //導入依賴的package包/類
private static Message convertJSONObjectToMessage(JSONObject jo, Class c, Registry<Class> r) {
    //System.out.println("JSON.convertJSONObjectToMessage: " + jo.toJSONString());
    try {
        Message result = (Message) c.newInstance();
        for (Field f : c.getFields()) {
            Class fc = getFieldClass(result, jo, f, r);
            Object lookup = jo.get(f.getName());
            if (lookup != null) {
                Object value = convertElementToField(lookup, fc, f, r);
                f.set(result, value);
            }
        }      
        return result;
    }
    catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }        
}
 
開發者ID:ZhouKanZ,項目名稱:SweepRobot,代碼行數:20,代碼來源:JSON.java


注:本文中的com.alibaba.fastjson.JSONObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。