本文整理匯總了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"));
}
}