本文整理匯總了Java中com.alibaba.fastjson.JSONObject.toString方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.toString方法的具體用法?Java JSONObject.toString怎麽用?Java JSONObject.toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.fastjson.JSONObject
的用法示例。
在下文中一共展示了JSONObject.toString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getIdGroup
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 查詢用戶所在分組
*
* @param openId 用戶的OpenID
* @return 用戶所屬的groupid
*/
public Integer getIdGroup(String openId) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("openid", openId);
String requestData = jsonObject.toString();
logger.info("request data " + requestData);
String resultStr = HttpUtils.post(GROUP_GETID_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);
int groupId = resultJson.getIntValue("groupid");
return groupId;
}
示例2: 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");
}
示例3: toString
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public String toString(){
JSONObject jsObj = new JSONObject();
jsObj.put("touser", openid);
jsObj.put("template_id", templateId);
jsObj.put("url", url);
JSONObject data = new JSONObject();
if(dataMap != null){
for(String key : dataMap.keySet()){
JSONObject item = new JSONObject();
item.put("value", dataMap.get(key));
item.put("color", color);
data.put(key,item);
}
}
jsObj.put("data", data);
return jsObj.toString();
}
示例4: sendFileMsg
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 發送多媒體文件
*
* @return
*/
public static String sendFileMsg(String touser, String toparty, String totag, int agentid, String media_id,
boolean safe) throws IOException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("touser", touser);// 成員ID列表(消息接收者,多個接收者用‘|’分隔,最多支持1000個)。特殊情況:指定為@all,則向關注該企業應用的全部成員發送
jsonObject.put("toparty", toparty);// 部門ID列表,多個接收者用‘|’分隔,最多支持100個。當touser為@all時忽略本參數
jsonObject.put("totag", totag);// 標簽ID列表,多個接收者用‘|’分隔。當touser為@all時忽略本參數
jsonObject.put("agentid", agentid + "");// 企業應用的id,整型。可在應用的設置頁麵查看
jsonObject.put("msgtype", "file");// 消息類型,此時固定為:text
JSONObject text = new JSONObject();
text.put("media_id", media_id);
jsonObject.put("file", text);// 消息內容
if (safe) {
jsonObject.put("safe", "1");// 表示是否是保密消息,0表示否,1表示是,默認0
} else {
jsonObject.put("safe", "0");// 表示是否是保密消息,0表示否,1表示是,默認0
}
System.out.println(jsonObject);
String urlStr = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="
+ WeiXinCompanyUtils.getToken();
String parameters = jsonObject.toString();
URL url = new URL(urlStr);
System.out.println("url:" + urlStr);
System.out.println("parameters:" + parameters);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setDoInput(true);
OutputStream output = conn.getOutputStream();
output.write(parameters.getBytes("utf-8"));
output.flush();
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
String s = null;
StringBuilder sb = new StringBuilder();
while ((s = reader.readLine()) != null) {
sb.append(s);
}
reader.close();
System.out.println(sb.toString());
return sb.toString();
}
示例5: buildContent
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public String buildContent(String roomName, String teamID, List<String> accounts, String teamName) {
JSONObject json = new JSONObject();
json.put(KEY_ID, ID);
JSONArray array = new JSONArray();
array.add(DemoCache.getAccount());
for (String account : accounts) {
array.add(account);
}
json.put(KEY_MEMBER, array);
json.put(KEY_TID, teamID);
json.put(KEY_RID, roomName);
json.put(KEY_TNAME, teamName);
return json.toString();
}
示例6: checkTransactionInfo
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public int checkTransactionInfo(String groupId, String taskId) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("g", groupId);
jsonObject.put("t", taskId);
Request request = new Request("ckg", jsonObject.toString());
String json = nettyService.sendMsg(request);
try {
return Integer.parseInt(json);
}catch (Exception e){
return -2;
}
}
示例7: updateGroup
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 修改分組名
*
* @param groupId 分組id
* @param name 分組名稱
* @throws WeChatException
*/
public void updateGroup(int groupId, String name) throws WeChatException {
JSONObject nameJson = new JSONObject();
JSONObject groupJson = new JSONObject();
nameJson.put("id", groupId);
nameJson.put("name", name);
groupJson.put("group", nameJson);
String requestData = groupJson.toString();
logger.info("request data " + requestData);
String resultStr = HttpUtils.post(GROUP_UPDATE_POST_URL + TokenProxy.accessToken(), requestData);
logger.info("return data " + resultStr);
WeChatUtil.isSuccess(resultStr);
}
示例8: membersUpdateGroup
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 移動用戶分組
*
* @param openId 用戶的OpenID
* @param groupId 分組id
* @throws WeChatException
*/
public void membersUpdateGroup(String openId, int groupId) throws WeChatException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("openid", openId);
jsonObject.put("to_groupid", groupId);
String requestData = jsonObject.toString();
logger.info("request data " + requestData);
String resultStr = HttpUtils.post(GROUP_MEMBERS_UPDATE_POST_URL + TokenProxy.accessToken(), requestData);
logger.info("return data " + resultStr);
WeChatUtil.isSuccess(resultStr);
}
示例9: membersDatchUpdateGroup
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
/**
* 批量移動用戶分組
*
* @param openIds 用戶唯一標識符openid的列表(size不能超過50)
* @param groupId 分組id
* @return 是否修改成功
* @throws WeChatException
*/
public void membersDatchUpdateGroup(String[] openIds, int groupId) throws WeChatException {
JSONObject jsonObject = new JSONObject();
jsonObject.put("openid_list", openIds);
jsonObject.put("to_groupid", groupId);
String requestData = jsonObject.toString();
logger.info("request data " + requestData);
String resultStr = HttpUtils.post(GROUP_MEMBERS_DATCHUPDATE_POST_URL + TokenProxy.accessToken(), requestData);
logger.info("return data " + resultStr);
WeChatUtil.isSuccess(resultStr);
}
示例10: getUserSig
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public String getUserSig(String identifier, long expire)throws QCloudException {
try {
Security.addProvider(new BouncyCastleProvider());
Reader reader = new CharArrayReader(imConfig.getPrivateKey().toCharArray());
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
PEMParser parser = new PEMParser(reader);
Object obj = parser.readObject();
parser.close();
PrivateKey privKeyStruct = converter.getPrivateKey((PrivateKeyInfo) obj);
String jsonString = "{"
+ "\"TLS.account_type\":\"" + 0 +"\","
+"\"TLS.identifier\":\"" + identifier +"\","
+"\"TLS.appid_at_3rd\":\"" + 0 +"\","
+"\"TLS.sdk_appid\":\"" + imConfig.getSdkAppId() +"\","
+"\"TLS.expire_after\":\"" + expire +"\","
+"\"TLS.version\": \"201512300000\""
+"}";
String time = String.valueOf(System.currentTimeMillis()/1000);
String SerialString =
"TLS.appid_at_3rd:" + 0 + "\n" +
"TLS.account_type:" + 0 + "\n" +
"TLS.identifier:" + identifier + "\n" +
"TLS.sdk_appid:" + imConfig.getSdkAppId() + "\n" +
"TLS.time:" + time + "\n" +
"TLS.expire_after:" + expire +"\n";
//Create Signature by SerialString
Signature signature = Signature.getInstance("SHA256withECDSA", "BC");
signature.initSign(privKeyStruct);
signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
byte[] signatureBytes = signature.sign();
String sigTLS = Base64.encodeBase64String(signatureBytes);
//Add TlsSig to jsonString
JSONObject jsonObject= JSON.parseObject(jsonString);
jsonObject.put("TLS.sig", (Object)sigTLS);
jsonObject.put("TLS.time", (Object)time);
jsonString = jsonObject.toString();
//compression
Deflater compresser = new Deflater();
compresser.setInput(jsonString.getBytes(Charset.forName("UTF-8")));
compresser.finish();
byte [] compressBytes = new byte [512];
int compressBytesLength = compresser.deflate(compressBytes);
compresser.end();
return new String(Base64Url.base64EncodeUrl(Arrays.copyOfRange(compressBytes,0,compressBytesLength)));
}catch (Exception e) {
throw new QCloudException(e);
}
}
示例11: getJson
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
protected String getJson(boolean result, String message, Object data) {
JSONObject resultjson = new JSONObject();
resultjson.put("result", Boolean.valueOf(result));
resultjson.put("message", message);
resultjson.put("data", data);
return resultjson.toString();
}
示例12: closeTransactionGroup
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@Override
public void closeTransactionGroup(final String groupId, final int state) {
JSONObject jsonObject = new JSONObject();
jsonObject.put("g", groupId);
jsonObject.put("s", state);
Request request = new Request("ctg", jsonObject.toString());
String json = nettyService.sendMsg(request);
logger.info("closeTransactionGroup-res-"+groupId+"->" + json);
}
示例13: toJsonString
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public String toJsonString() {
JSONObject jsonObject = new JSONObject();
jsonObject.put("g", getGroupId());
jsonObject.put("st", getStartTime());
jsonObject.put("o",getHasOver());
jsonObject.put("nt", getNowTime());
JSONArray jsonArray = new JSONArray();
jsonObject.put("l", jsonArray);
return jsonObject.toString();
}
示例14: TransactionHandler
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
public TransactionHandler(NettyService nettyService, int delay) {
this.nettyService = nettyService;
this.delay = delay;
//心跳包
JSONObject heartJo = new JSONObject();
heartJo.put("a", "h");
heartJo.put("k", "h");
heartJo.put("p", "{}");
heartJson = heartJo.toString();
}
示例15: test02
import com.alibaba.fastjson.JSONObject; //導入方法依賴的package包/類
@RequestMapping(value = "/test02",method = RequestMethod.GET)
public String test02(@ModelAttribute User user) {
users.put(user.getId(), user);
JSONObject jsonObject = JSONObject.parseObject(JSON.toJSONString(users));
return jsonObject.toString();
}