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