本文整理汇总了Java中com.alibaba.fastjson.JSONObject.parseObject方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.parseObject方法的具体用法?Java JSONObject.parseObject怎么用?Java JSONObject.parseObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSONObject
的用法示例。
在下文中一共展示了JSONObject.parseObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testClone
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Test
public void testClone() throws Exception {
JSONObject.parseObject("{\"ref\":\"100\",\"type\":\"div\",\"attr\":{},\"style\":{\"backgroundColor\":\"rgb(40,96,144)\",\"fontSize\":40,\"color\":\"#ffffff\",\"paddingRight\":30,\"paddingLeft\":30,\"paddingBottom\":20,\"paddingTop\":20}}");
JSONObject obj = new JSONObject();
obj.put("ref","101");
obj.put("type","test");
JSONArray event = new JSONArray();
event.add("click");
obj.put("event",event);
dom.parseFromJson(obj);
WXDomObject clone = dom.clone();
assertEquals(clone.getRef(),"101");
assertEquals(clone.getType(),"test");
}
示例2: pushMsg
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static Map<String, Object> pushMsg(String accessToken, String touser, String templateId, String formId, List<TemplateMsg> value) {
String url = String.format(HttpApiUrl.SEND_MSG, accessToken);
Map<String, Object> data = new HashMap<>();
data.put("touser", touser);
data.put("template_id", templateId);
data.put("form_id", formId);
Map<String, Object> msgs = new HashMap<>();
for (int i = 0; i < value.size(); i++) {
TemplateMsg msg = value.get(i);
msgs.put("keyword" + (i + 1), msg);
}
data.put("data", msgs);
String json = new JSONObject(data).toJSONString();
System.out.println(json);
String res = HttpUtils.postJson(url, json);
LogUtils.logResult("发送模板消息", res);
Map<String, Object> map = null;
try {
map = JSONObject.parseObject(res);
} catch (Exception e) {
e.printStackTrace();
return null;
}
return map;
}
示例3: queryBranch
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/** 查询支行信息 */
public JSONArray queryBranch(LianlianBankType bankType, String cityCode) {
JSONObject post = new JSONObject();
post.put("oid_partner", this.merchantId);
post.put("sign_type", this.signType);
post.put("card_no", "");
post.put("bank_code", bankType.getCode());
post.put("brabank_name", "银行");// 关键字
post.put("city_code", cityCode);
// 加签名
String sign = LianlianPayUtil.addSign(post, this.privateKey, this.md5Key);
post.put("sign", sign);
String text = this.sendHttpPost(this.queryUrl, post.toString());
logger.info("连连支付返回:" + text);
JSONObject result = JSONObject.parseObject(text);
if (!"0000".equals(result.getString("ret_code"))) {
return null;
}
return result.getJSONArray("card_list");
}
示例4: shortUrl
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 长链接转短链接接口
*
* @param longUrl 需要转换的长链接
* @return
*/
public String shortUrl(String longUrl) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("action", "long2short");
jsonObject.put("long_url", longUrl);
String requestData = jsonObject.toString();
logger.info("request data " + requestData);
String resultStr = HttpUtils.post(SHORTURL_POST_URL + TokenProxy.accessToken(), requestData);
logger.info("return data " + resultStr);
try {
WeChatUtil.isSuccess(resultStr);
} catch (WeChatException e) {
logger.error(e.getMessage());
e.printStackTrace();
return null;
}
JSONObject resultJson = JSONObject.parseObject(resultStr);
return resultJson.getString("short_url");
}
示例5: onReceive
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
String action = context.getPackageName() + NimIntent.ACTION_RECEIVE_CUSTOM_NOTIFICATION;
if (action.equals(intent.getAction())) {
// 从intent中取出自定义通知
CustomNotification notification = (CustomNotification) intent.getSerializableExtra(NimIntent.EXTRA_BROADCAST_MSG);
try {
JSONObject obj = JSONObject.parseObject(notification.getContent());
if (obj != null && obj.getIntValue("id") == 2) {
// 加入缓存中
CustomNotificationCache.getInstance().addCustomNotification(notification);
// Toast
String content = obj.getString("content");
String tip = String.format("自定义消息[%s]:%s", notification.getFromAccount(), content);
Toast.makeText(context, tip, Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
LogUtil.e("demo", e.getMessage());
}
// 处理自定义通知消息
LogUtil.i("demo", "receive custom notification: " + notification.getContent() + " from :" + notification.getSessionId() + "/" + notification.getSessionType());
}
}
示例6: convert
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public Object convert(Object obj, Field field, Map<String, Object> excelRecordMap) {
logger.trace("field: " + field.getName() +
", obj: " + obj +
" run ValueMapConvertor");
String jsonStr = field.getAnnotation(ValueMap.class).value();
if (StringUtils.isBlank(jsonStr))
throw new RuntimeException("field注解ValueMap值为空,filed:" + field.getName());
logger.debug(jsonStr);
JSONObject json;
try {
json = JSONObject.parseObject(jsonStr);
} catch (Exception e) {
throw new RuntimeException("field注解ValueMap值不是有效json,filed:" + field.getName(), e);
}
if (obj != null) {
obj = json.get(obj.toString());
}
return obj;
}
示例7: getByMchId
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public JSONObject getByMchId(String mchId) {
Map<String,Object> paramMap = new HashMap<>();
paramMap.put("mchId", mchId);
String jsonParam = RpcUtil.createBaseParam(paramMap);
Map<String, Object> result = selectMchInfo(jsonParam);
String s = RpcUtil.mkRet(result);
if(s==null) return null;
return JSONObject.parseObject(s);
}
示例8: setHeader
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 设置请求头
*
* @author gaoxianglong
*/
public static void setHeader(HttpRequestBase request, String headers, ContentType contentType, String charset) {
if (null == request) {
return;
}
request.setHeader(HTTP.CONTENT_TYPE,
Optional.ofNullable(contentType.type).orElseGet(() -> ContentType.APPLICATION_XML.type) + ";"
+ Optional.ofNullable(charset).orElseGet(() -> "UTF-8"));
if (!StringUtils.isEmpty(headers)) {
/* 设置请求头参数 */
JSONObject jsonObj = JSONObject.parseObject(JSONObject.parseObject(headers).get("header").toString());
jsonObj.keySet().stream().forEach(key -> request.setHeader(key, jsonObj.getString(key)));
}
}
示例9: getRequestMap
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* @Title: getRequestMap
* @Description: TODO(获取表单提交信息,即将表单提交的数据转换为map格式的数据,通常用于添加、修改等请求)
* @author [email protected] (苟志强)
* @date 2017-6-5 下午6:05:13
* @param request HttpServletRequest对象
* @return 表单map对象
*/
@SuppressWarnings("unchecked")
public static Map<String, Object> getRequestMap(HttpServletRequest request){
Map<?, ?> requestParams = request.getParameterMap();
Map<String, Object> mapp=new HashMap<String, Object>();
Map<String, Object> map = new HashMap<String,Object>();
for (Iterator<?> iter = requestParams.keySet().iterator(); iter.hasNext();) {
String name = (String) iter.next();
String[] values = (String[]) requestParams.get(name);
String valueStr = "";
for (int i = 0; i < values.length; i++) {
valueStr = (i == values.length - 1)?valueStr+values[i]:valueStr+values[i]+",";
}
//乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
map.put(name, valueStr);
//解决前台采用
if(map.get("httpType")!=null && map.get("httpType").equals("http")){
String params=map.get("data")+"";
if(params!=null && !params.equals("") && !params.equals("null")){
if(mapp==null){
mapp=new HashMap<String, Object>();
}
mapp=JSONObject.parseObject(params,mapp.getClass());
}
}else{
mapp=map;
}
}
return mapp;
}
示例10: httpsRequest
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* @param requestUrl
* @param requestMethod
* @param outputStr
* @return
*/
public static JSONObject httpsRequest(String requestUrl, String requestMethod, String outputStr) {
JSONObject jsonObject = null;
StringBuffer buffer = new StringBuffer();
try {
TrustManager[] tm = {new MyX509TrustManager()};
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
SSLSocketFactory ssf = sslContext.getSocketFactory();
URL url = new URL(requestUrl);
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();
httpUrlConn.setSSLSocketFactory(ssf);
httpUrlConn.setDoOutput(true);
httpUrlConn.setDoInput(true);
httpUrlConn.setUseCaches(false);
httpUrlConn.setRequestMethod(requestMethod);
if ("GET".equalsIgnoreCase(requestMethod))
httpUrlConn.connect();
if (null != outputStr) {
OutputStream outputStream = httpUrlConn.getOutputStream();
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
InputStream inputStream = httpUrlConn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
bufferedReader.close();
inputStreamReader.close();
inputStream.close();
inputStream = null;
httpUrlConn.disconnect();
jsonObject = JSONObject.parseObject(buffer.toString());
} catch (ConnectException ce) {
ce.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return jsonObject;
}
示例11: buildDottedNameSpace
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public String buildDottedNameSpace(String dataSourceInfo){
String dbName = (String)(this.properties.get(DBConfiguration.DataSourceInfo.DB_NAME));
JSONObject ds=JSONObject.parseObject(dataSourceInfo);
JSONObject payload = ds.getJSONObject(DataPullConstants.FullPullInterfaceJson.PAYLOAD_KEY);
// String dbSchema = (String)(this.properties.get(DBConfiguration.DataSourceInfo.DB_SCHEMA));
// String tableName = (String)(this.properties.get(DBConfiguration.DataSourceInfo.TABLE_NAME));
String dbSchema = payload.getString(DataPullConstants.FULL_DATA_PULL_REQ_PAYLOAD_SCHEMA_NAME);
String tableName = payload.getString(DataPullConstants.FULL_DATA_PULL_REQ_PAYLOAD_TABLE_NAME);
String version = payload.getString(DataPullConstants.FullPullInterfaceJson.VERSION_KEY);
return String.format("%s.%s.%s.%s", dbName, dbSchema, tableName, version);
}
示例12: httpsRequest
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static JSONObject httpsRequest(String requestUrl, String requestMethod, String outputStr) {
JSONObject jsonObject = null;
try {
// 创建SSLContext对象,并使用我们指定的信任管理器初始化
TrustManager[] tm = { new HttpsX509TrustManager() };
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
// 从上述SSLContext对象中得到SSLSocketFactory对象
SSLSocketFactory ssf = sslContext.getSocketFactory();
URL url = new URL(requestUrl);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setSSLSocketFactory(ssf);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Connection", "keep-alive");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36");
conn.setUseCaches(false);
conn.setRequestProperty("Content-Type", "application/json;;charset=UTF-8");
// 设置请求方式(GET/POST)
conn.setRequestMethod(requestMethod);
// 当outputStr不为null时向输出流写数据
if (null != outputStr) {
OutputStream outputStream = conn.getOutputStream();
// 注意编码格式
outputStream.write(outputStr.getBytes("UTF-8"));
outputStream.close();
}
// 从输入流读取返回内容
InputStream inputStream = conn.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(inputStream, "utf-8");
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String str = null;
StringBuffer buffer = new StringBuffer();
while ((str = bufferedReader.readLine()) != null) {
buffer.append(str);
}
// 释放资源
bufferedReader.close();
inputStreamReader.close();
inputStream.close();
inputStream = null;
conn.disconnect();
jsonObject = JSONObject.parseObject(buffer.toString());
} catch (ConnectException ce) {
ce.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return jsonObject;
}
示例13: getLoginMemberInfoJson
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**获取存储会员信息*/
public JSONObject getLoginMemberInfoJson(){
if(session==null) return null;
JSONObject memberJson = null;
Object memberObj = session.getAttribute(Statics.MEMBER_LOGIN_INFO_KEY);
if (memberObj!=null) {
memberJson = JSONObject.parseObject(JSONObject.toJSONString(memberObj));
}
return memberJson;
}
示例14: json2object
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public IObject json2object(String jsonStr) {
if (jsonStr.length() < 2) {
throw new IllegalStateException(
"Can\'t decode AVAObject. JSON String is too short. Len: " + jsonStr.length());
} else {
JSONObject jso = JSONObject.parseObject(jsonStr);
return this.decodeSFSObject((JSONObject) jso);
}
}
示例15: channelRead0
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame frame)
throws Exception {
UserInfo userInfo = UserInfoManager.getUserInfo(ctx.channel());
if (userInfo != null && userInfo.isAuth()) {
JSONObject json = JSONObject.parseObject(frame.text());
// 广播返回用户发送的消息文本
UserInfoManager.broadcastMess(userInfo.getUserId(), userInfo.getNick(), json.getString("mess"));
}
}