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