本文整理汇总了Java中com.alibaba.fastjson.JSONObject.getLong方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.getLong方法的具体用法?Java JSONObject.getLong怎么用?Java JSONObject.getLong使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.fastjson.JSONObject
的用法示例。
在下文中一共展示了JSONObject.getLong方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initTicket
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static void initTicket() {
if (jsapi_ticket == null || expires_in == null || ticketTime == null
|| System.currentTimeMillis() - ticketTime >= expires_in) {
String urlStr = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token="
+ WeiXinCompanyUtils.getToken();
try {
URL url = new URL(urlStr);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setDoInput(true);
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
String s = null;
while ((s = reader.readLine()) != null) {
sb.append(s);
}
reader.close();
JSONObject jsonObject = JSON.parseObject(sb.toString());
String errcode = jsonObject.get("errcode").toString();
if (errcode.equals("0")) {
jsapi_ticket = jsonObject.get("ticket").toString();
expires_in = jsonObject.getLong("expires_in");
ticketTime = System.currentTimeMillis();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
示例2: handle
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
@Override
public void handle(Tuple tuple) {
EmitData data = (EmitData) tuple.getValueByField(Constants.EmitFields.DATA);
List<PairWrapper<String, Object>> wrapperList = data.get(EmitData.MESSAGE);
DataTable table = data.get(EmitData.DATA_TABLE);
MetaVersion ver = data.get(EmitData.VERSION);
for (PairWrapper<String, Object> wrapper : wrapperList) {
Object packet = wrapper.getPairValue("PACKET");
JSONObject json = JSON.parseObject(packet.toString());
String dbSchema = wrapper.getPairValue("SCHEMA_NAME").toString();
String tableName = wrapper.getPairValue("TABLE_NAME").toString();
String pos = wrapper.getProperties(Constants.MessageBodyKey.POS).toString();
// oracle 数据格式:2017-03-24 14:28:00.995660,mysql格式:2017-03-24 14:28:00.995
// 暂时不要统一
//String opts = wrapper.getProperties(Constants.MessageBodyKey.OP_TS).toString().substring(0, 23);
String opts = wrapper.getProperties(Constants.MessageBodyKey.OP_TS).toString();
long time = json.getLong("time");
long txTime = json.getLong("txTime");
String targetTopic = listener.getTargetTopic(dbSchema, tableName);
// 发送Heartbeat
listener.sendHeartbeat(message(table, ver, pos, opts), targetTopic, buildKey(time + "|" + txTime, table, ver));
}
}
示例3: parseJsonObject
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private JSONObject parseJsonObject(String key, byte[] bytes) {
if (bytes == null) {
return null;
}
String loadString = CompressUtil.decompress(bytes);
JSONObject jsonObject = JSONObject.parseObject(loadString);
if (jsonObject == null) {
return null;
}
long cacheTimestamp = jsonObject.getLong(TIMESTAMP);
if (System.currentTimeMillis() - cacheTimestamp > mConfig.getMemoryCacheTime()) {
overdue(key);
return null;
}
return jsonObject;
}
示例4: initToken
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private static void initToken() {
if (tokenTime == null || tokenExpire == null || System.currentTimeMillis() - tokenTime >= tokenExpire
|| token == null) {
String uriString = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
StringBuffer sb = new StringBuffer();
sb.append(uriString);
sb.append("?corpid=").append(PropertiesUtil.getString("WX_QY_CORPID"));
sb.append("&corpsecret=").append(PropertiesUtil.getString("WX_QY_CORPSECRET"));
try {
System.out.println(sb);
URL url = new URL(sb.toString());
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
InputStreamReader inputStreamReader = new InputStreamReader(httpsURLConnection.getInputStream());
int responseInt = inputStreamReader.read();
StringBuffer stringBuffer = new StringBuffer();
while (responseInt != -1) {
stringBuffer.append((char) responseInt);
responseInt = inputStreamReader.read();
}
String tokenString = stringBuffer.toString();
System.out.println(stringBuffer);
JSONObject jsonObject = JSON.parseObject(tokenString);
if (jsonObject.containsKey("access_token")) {
tokenTime = System.currentTimeMillis();
token = jsonObject.getString("access_token");
tokenExpire = jsonObject.getLong("expires_in");
} else {
// TODO 验证错误
System.out.println(jsonObject.get("errcode"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
示例5: initToken
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private static void initToken() {
if (tokenTime == null || tokenExpire == null || System.currentTimeMillis() - tokenTime >= tokenExpire) {
String uriString = "https://api.weixin.qq.com/cgi-bin/token?grant_type=" + grantType + "&appid="
+ PropertiesUtil.getString("WX_PUBLIC_APPID") + "&secret="
+ PropertiesUtil.getString("WX_PUBLIC_SECRET");
try {
URL url = new URL(uriString);
HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
InputStreamReader inputStreamReader = new InputStreamReader(httpsURLConnection.getInputStream());
int responseInt = inputStreamReader.read();
StringBuffer stringBuffer = new StringBuffer();
while (responseInt != -1) {
stringBuffer.append((char) responseInt);
responseInt = inputStreamReader.read();
}
String tokenString = stringBuffer.toString();
JSONObject jsonObject = JSON.parseObject(tokenString);
if (jsonObject.containsKey("access_token")) {
tokenTime = System.currentTimeMillis();
token = jsonObject.getString("access_token");
tokenExpire = jsonObject.getLong("expires_in");
} else {
// TODO 验证错误
System.out.println(jsonObject.get("errcode"));
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
示例6: fromJsonString
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
public static LCIMConversationItem fromJsonString(String json) {
LCIMConversationItem item = new LCIMConversationItem();
JSONObject jsonObject = null;
try {
jsonObject = JSONObject.parseObject(json);
item.conversationId = jsonObject.getString(ITEM_KEY_CONVCERSATION_ID);
item.unreadCount = jsonObject.getInteger(ITEM_KEY_UNREADCOUNT);
item.updateTime = jsonObject.getLong(ITEM_KEY_UNDATE_TIME);
} catch (Exception e) {
LCIMLogUtils.logException(e);
}
return item;
}
示例7: getMemMetrics
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 内存
* @param containerName
* @param container
* @return
* @throws IOException
*/
private List<CollectObject> getMemMetrics(String containerName,JSONObject container,JSONObject machineInfo) throws IOException {
List<CollectObject> collectObjectList = new ArrayList<>();
boolean hasMemory = container.getJSONObject("spec").getBoolean("has_memory");
collectObjectList.add(new CollectObject(containerName,"has_memory",hasMemory ? "1" : "0",""));
if(hasMemory){
long machineMemory = machineInfo.getLong("memory_capacity");//机器总内存
long limitMemory = container.getJSONObject("spec").getJSONObject("memory").getLong("limit");//容器的内存限制大小
if(limitMemory > machineMemory || limitMemory < 0){
//若内存限制大于机器总内存或小于0,使用机器总内存为总内存大小
limitMemory = machineMemory;
}
JSONArray stats = container.getJSONArray("stats");
int count = stats.size();
JSONObject stat = stats.getJSONObject(count - 1);
JSONObject memory = stat.getJSONObject("memory");
long usage = memory.getLong("usage");
long cache = memory.getLong("cache");
collectObjectList.add(new CollectObject(containerName,"mem.size.usage", String.valueOf(Maths.div(usage,1024 * 1024)),""));
collectObjectList.add(new CollectObject(containerName,"mem.size.cache", String.valueOf(Maths.div(cache,1024 * 1024)),""));
collectObjectList.add(new CollectObject(containerName,"mem.usage.rate", String.valueOf(Maths.div(usage,limitMemory,5) * 100),""));
collectObjectList.add(new CollectObject(containerName,"mem.cache.rate", String.valueOf(Maths.div(cache,limitMemory,5) * 100),""));
}
return collectObjectList;
}
示例8: decrypt
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* @Title: decrypt
* @Description: TODO(密文解码)
* @author [email protected] (苟志强)
* @date 2017-5-31 下午5:32:36
* @param public_key 用户公钥
* @param ciphertext 密文字符串
* @return 解密结果json对象
*/
public JSONObject decrypt(String public_key,String ciphertext){
JSONObject json = new JSONObject();
//获取加密key
JSONObject json_pk = checkUserPublicKey(public_key);
if(json_pk.getLong("state")==10000){
String key = json_pk.getString("key");
try {
String express = null;
if(ciphertext!=null&&!"".equals(ciphertext)){
BASE64Decoder decoder = new BASE64Decoder();
byte[] key_by = key.getBytes("utf-8");
String ex_str = URLDecoder.decode(new String(decoder.decodeBuffer(ciphertext), "utf-8"),"utf-8");
if(ex_str.indexOf("[")==0)ex_str=ex_str.substring(1);
if(ex_str.indexOf("]")==ex_str.length()-1)ex_str=ex_str.substring(0,ex_str.length()-1);
String[] ex_by_str = ex_str.split(",");
byte[] ex_by = new byte[ex_by_str.length];
for (int i = 0,j=0,len = ex_by.length; i < len; i++,j++) {
ex_by[i] = (byte) (Byte.parseByte(ex_by_str[i].trim()) - key_by[j]);
if(j >= key_by.length-1){
j = 0;
}
}
express = new String(ex_by, "utf-8");
express = URLDecoder.decode(express,"utf-8");
}
if(express==null)throw new Exception();
json.put("state", 10000);
// json.put("key", key);
json.put("state_msg", "解密成功!");
json.put("express", express);
} catch (Exception e) {
json.put("state", 10001);
json.put("state_msg", "对明文进行解密失败,详细:"+e.toString());
}
}else{
json = json_pk;
}
return json;
}
示例9: encrypt
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* @Title: encrypt
* @Description: TODO(明文加密)
* @author [email protected] (苟志强)
* @date 2017-5-31 下午4:53:38
* @param private_key 用户私钥
* @param express 明文字符串
* @return 加密结果json对象
*/
public JSONObject encrypt(String private_key,String express){
JSONObject json = new JSONObject();
//获取加密key
JSONObject json_pk = checkUserPrivateKey(private_key);
if(json_pk.getLong("state")==10000){
String key = json_pk.getString("key");
try {
String ciphertext = null;
if(express!=null&&!"".equals(express)){
express = URLEncoder.encode(express,"utf-8");
byte[] key_by = key.getBytes("utf-8");
byte[] ex_by = express.getBytes("utf-8");
for (int i = 0,j=0,len = ex_by.length; i < len; i++,j++) {
ex_by[i] += key_by[j];
if(j >= key_by.length-1){
j = 0;
}
}
ciphertext = new BASE64Encoder().encode(Arrays.toString(ex_by).getBytes());
}
if(ciphertext==null)throw new Exception();
json.put("state", 10000);
// json.put("key", key);
json.put("state_msg", "加密成功!");
json.put("ciphertext", ciphertext);
} catch (Exception e) {
json.put("state", 10001);
json.put("state_msg", "对明文进行加密失败,详细:"+e.toString());
}
}else{
json = json_pk;
}
return json;
}
示例10: getNetMetrics
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private List<CollectObject> getNetMetrics(String containerName,JSONObject container){
List<CollectObject> collectObjectList = new ArrayList<>();
boolean hasNetwork = container.getJSONObject("spec").getBoolean("has_network");
collectObjectList.add(new CollectObject(containerName,"has_network",hasNetwork ? "1" : "0",""));
if(hasNetwork){
JSONArray stats = container.getJSONArray("stats");
int count = stats.size();
JSONObject stat = stats.getJSONObject(count - 1);
JSONObject network = stat.getJSONObject("network");
JSONArray interfaces = network.getJSONArray("interfaces");
for (Object ifObj : interfaces) {
JSONObject ifJson = (JSONObject) ifObj;
String ifName = ifJson.getString("name");
String tag = "ifName=" + ifName;
long rxBytes = ifJson.getLong("rx_bytes");
long rxPackets = ifJson.getLong("rx_packets");
long rxErrors = ifJson.getLong("rx_errors");
long rxDropped = ifJson.getLong("rx_dropped");
long txBytes = ifJson.getLong("tx_bytes");
long txPackets = ifJson.getLong("tx_packets");
long txErrors = ifJson.getLong("tx_errors");
long txDropped = ifJson.getLong("tx_dropped");
collectObjectList.add(new CollectObject(containerName,"net.if.in.bytes",String.valueOf(rxBytes),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.in.packets",String.valueOf(rxPackets),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.in.errors",String.valueOf(rxErrors),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.in.dropped",String.valueOf(rxDropped),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.bytes",String.valueOf(rxBytes),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.packets",String.valueOf(rxPackets),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.errors",String.valueOf(rxErrors),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.dropped",String.valueOf(rxDropped),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.out.bytes",String.valueOf(txBytes),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.out.packets",String.valueOf(txPackets),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.out.errors",String.valueOf(txErrors),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.out.dropped",String.valueOf(txDropped),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.bytes",String.valueOf(txBytes),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.packets",String.valueOf(txPackets),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.errors",String.valueOf(txErrors),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.dropped",String.valueOf(txDropped),tag,CounterType.COUNTER));
}
}
return collectObjectList;
}
示例11: allQueueData
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 所有的队列监控数据
* @param rabbitMQ
* @return
*/
private List<DetectResult.Metric> allQueueData(RabbitMQ rabbitMQ) {
List<DetectResult.Metric> result = new ArrayList<>();
String apiBody = getAPIResult(rabbitMQ,"api/queues");
if (apiBody != null){
if (apiBody.trim().equals("[]")){
log.info("当前RabbitMQ({}:{})无队列数据",rabbitMQ.getIp(),rabbitMQ.getPort());
}else {
JSONArray jsonArray = JSONArray.parseArray(apiBody);
//队列数
result.add(new DetectResult.Metric("queues_count",String.valueOf(jsonArray.size()),CounterType.GAUGE,""));
long consumersCountTotal = 0;
for (Object o : jsonArray) {
JSONObject jsonObject = (JSONObject) o;
String queueName = jsonObject.getString("name");
String vHost = jsonObject.getString("vhost");
if (queueName == null || vHost == null) {
continue;
}
String tag = String.format("queue=%s,vhost=%s",queueName,vHost);
consumersCountTotal += jsonObject.getLong("consumers");
//队列消费者接收新消息的时间的比例
utilForParsingJSON(result,"queues_consumer_utilisation","consumer_utilisation",jsonObject,CounterType.GAUGE,tag);
//队列中的消息总数
utilForParsingJSON(result,"queues_messages","messages",jsonObject,CounterType.GAUGE,tag);
//发送给客户端单但至今还未被确认的消息数量
utilForParsingJSON(result,"queues_messages_unacknowledged","messages_unacknowledged",jsonObject,CounterType.GAUGE,tag);
//每秒发送给客户端但至今还未被确认的消息数量
utilForParsingJSON(result,"queues_messages_unacknowledged_rate","messages_unacknowledged_details->rate",jsonObject,CounterType.GAUGE,tag);
//准备发送给客户端的数量
utilForParsingJSON(result,"queues_messages_ready","messages_ready",jsonObject,CounterType.GAUGE,tag);
//每秒准备发送给客户端的数量
utilForParsingJSON(result,"queues_messages_ready_rate","messages_ready_details->rate",jsonObject,CounterType.GAUGE,tag);
//发布的消息数量
utilForParsingJSON(result,"queues_messages_publish_count","message_stats->publish",jsonObject,CounterType.GAUGE,tag);
//每秒发布的消息数量
utilForParsingJSON(result,"queues_messages_publish_count_rate","message_stats->publish_details->rate",jsonObject,CounterType.GAUGE,tag);
//发送给客户端并确认的消息数量
utilForParsingJSON(result,"queues_messages_ack_count","message_stats->ack",jsonObject,CounterType.GAUGE,tag);
//每秒发送给客户端并确认的消息数量
utilForParsingJSON(result,"queues_messages_ack_count_rate","message_stats->ack_details->rate",jsonObject,CounterType.GAUGE,tag);
//消费者接收并响应的消息数量
utilForParsingJSON(result,"queues_messages_deliver_count","message_stats->deliver",jsonObject,CounterType.GAUGE,tag);
//每秒消费者接收并响应的消息数量
utilForParsingJSON(result,"queues_messages_deliver_count_rate","message_stats->deliver_details->rate",jsonObject,CounterType.GAUGE,tag);
}
//消费者总数量
result.add(new DetectResult.Metric("queues_consumers_count_total",String.valueOf(consumersCountTotal),CounterType.GAUGE,""));
}
}
return result;
}
示例12: getNewsList
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 获取新闻列表
*
* @param keyword
* @param page
* @return
*/
public static List<News> getNewsList(String keyword, int page)
{
List<News> newsList = new ArrayList<News>();
String path = "http://m.baidu.com/news?tn=bdapisearch&word=" + keyword + "&pn=" + page * 20
+ "&rn=20&t=1386838893136";
AsyncHttpClient asyncHttpClient = Wo2bAsyncHttpClient.newAsyncHttpClient();
SyncHttpResponse httpResponse = SyncHttpClient.getSync(asyncHttpClient, path, null);
if (httpResponse == null || !httpResponse.isOK())
{
return null;
}
String response = httpResponse.getContent();
if (response == null)
{
return null;
}
JSONObject responseJson = JSON.parseObject(response);
JSONArray jsonArray = responseJson.getJSONArray("list");
if (jsonArray == null)
{
return newsList;
}
JSONObject jsonObject = null;
News news = null;
int count = jsonArray.size();
for (int i = 0; i < count; i++)
{
jsonObject = jsonArray.getJSONObject(i);
news = new News();
news.setTitle(jsonObject.getString("title"));
news.setSource(jsonObject.getString("author"));
news.setUrl(jsonObject.getString("url"));
news.setPhotoUrl(jsonObject.getString("imgUrl"));
Long sortTime = jsonObject.getLong("sortTime") * 1000;
String date = DateUtils.getStringByStyle(sortTime, "yyyy-MM-dd HH:mm");
news.setDate(date);
newsList.add(news);
}
return newsList;
}
示例13: load
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
private void load(JSONObject data) {
path = data.getString(KEY_PATH);
md5 = data.getString(KEY_MD5);
url = data.getString(KEY_URL);
size = data.containsKey(KEY_SIZE) ? data.getLong(KEY_SIZE) : 0;
}
示例14: getLongFromDataByKey
import com.alibaba.fastjson.JSONObject; //导入方法依赖的package包/类
/**
* 根据key获取返回对象data中的长整数(只是第一层key),需要soa响应状态码是0
*
* @param result
* @param key
* @return
* @author xuxiao
* @created 2014年5月7日 下午6:00:25
*/
public static Long getLongFromDataByKey(final String result, final String key) {
final JSONObject data = getDataObj(result);
if (null != data) {
return data.getLong(key);
} else {
return null;
}
}