Java Code Examples for com.alibaba.fastjson.JSONObject#getDouble()

The following examples show how to use com.alibaba.fastjson.JSONObject#getDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AVIMAudioMessage.java    From java-unified-sdk with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseAdditionalMetaData(final Map<String, Object> meta, JSONObject response) {
  if (null == meta || null == response) {
    return;
  }
  JSONObject formatInfo = response.getJSONObject("format");
  if (formatInfo.containsKey("format_name")) {
    String fileFormat = formatInfo.getString("format_name");
    meta.put(FORMAT, fileFormat);
  }
  if (formatInfo.containsKey("duration")) {
    Double durationInDouble = formatInfo.getDouble("duration");
    meta.put(DURATION, AVUtils.normalize2Double(2, durationInDouble));
  }
  if (formatInfo.containsKey("FILE_SIZE")) {
    long size = formatInfo.getLong(FILE_SIZE);
    meta.put(FILE_SIZE, size);
  }
}
 
Example 2
Source File: AVIMVideoMessage.java    From java-unified-sdk with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseAdditionalMetaData(final Map<String, Object> meta, JSONObject response) {
  if (null == meta || null == response) {
    return;
  }
  JSONObject formatInfo = response.getJSONObject("format");
  if (null != formatInfo) {
    if (formatInfo.containsKey("format_name")) {
      String fileFormat = formatInfo.getString("format_name");
      meta.put(FORMAT, fileFormat);
    }
    if (formatInfo.containsKey("duration")) {
      Double durationInDouble = formatInfo.getDouble("duration");
      meta.put(DURATION, AVUtils.normalize2Double(2, durationInDouble));
    }
    if (formatInfo.containsKey(FILE_SIZE)) {
      long size = formatInfo.getLong(FILE_SIZE);
      meta.put(FILE_SIZE, size);
    }
  }
}
 
Example 3
Source File: AlertMessageSchedule.java    From redis-manager with Apache License 2.0 6 votes vote down vote up
private AlertRecord buildNodeInfoAlertRecord(Group group, Cluster cluster, NodeInfo nodeInfo, AlertRule rule) {
    JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(nodeInfo));
    AlertRecord record = new AlertRecord();
    String alertKey = rule.getRuleKey();
    String nodeInfoField = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, alertKey);
    Double actualVal = jsonObject.getDouble(nodeInfoField);
    record.setGroupId(group.getGroupId());
    record.setGroupName(group.getGroupName());
    record.setClusterId(cluster.getClusterId());
    record.setClusterName(cluster.getClusterName());
    record.setRuleId(rule.getRuleId());
    record.setRedisNode(nodeInfo.getNode());
    record.setAlertRule(rule.getRuleKey() + getCompareSign(rule.getCompareType()) + rule.getRuleValue());
    record.setActualData(rule.getRuleKey() + EQUAL_SIGN + actualVal);
    record.setCheckCycle(rule.getCheckCycle());
    record.setRuleInfo(rule.getRuleInfo());
    record.setClusterAlert(rule.getClusterAlert());
    return record;
}
 
Example 4
Source File: ActionController.java    From UIAutomatorWD with MIT License 6 votes vote down vote up
private static boolean drag(JSONObject args) throws Exception {
    String elementId = args.getString("element");
    Double fromX = args.getDouble("fromX");
    Double fromY = args.getDouble("fromY");
    Double toX = args.getDouble("toX");
    Double toY = args.getDouble("toY");
    double duration = args.getDoubleValue("duration");
    int steps = (int) Math.round(duration * 40);
    if (elementId != null) {
        Element el = elements.getElement(elementId);
        return el.drag(toX.intValue(), toY.intValue(), steps);
    } else {
        boolean res = mDevice.drag(fromX.intValue(), fromY.intValue(), toX.intValue(), toY.intValue(), steps);
        Thread.sleep(steps * 100);
        return res;
    }
}
 
Example 5
Source File: JsonUtils.java    From lorne_core with Apache License 2.0 6 votes vote down vote up
public static double getDouble(String json, String key,
                           double defaultVal) {
    JSONObject jsonObject = JSONObject.parseObject(json);
    try {
        if (jsonObject == null) {
            return defaultVal;
        }
        if (jsonObject.containsKey(key)) {
            return jsonObject.getDouble(key);
        } else {
            return defaultVal;
        }
    } catch (Exception e) {
        return defaultVal;
    }
}
 
Example 6
Source File: FastJsonUtils.java    From Java-API-Test-Examples with Apache License 2.0 5 votes vote down vote up
/***
 * 解析为双精度
 *
 * @param jsonString json字符串
 * @param key 关键字
 * @return  返回值
 */
public static Double formDouble(String jsonString, String key) {
    try {
        if (jsonString != null && jsonString.length() > 0) {
            JSONObject jsonObject = JSONObject.parseObject(jsonString);
            return jsonObject.getDouble(key);
        } else {
            return null;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 7
Source File: JSONUtil.java    From easyweb-shiro with MIT License 5 votes vote down vote up
/**
 * 得到Double类型的值
 */
public static Double getDouble(String json, String key) {
    Double result = null;
    try {
        JSONObject jsonObject = JSON.parseObject(json);
        result = jsonObject.getDouble(key);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
Example 8
Source File: AlertMessageSchedule.java    From redis-manager with Apache License 2.0 5 votes vote down vote up
/**
 * 校验监控指标是否达到阈值
 *
 * @param nodeInfo
 * @param alertRule
 * @return
 */
private boolean isNotify(NodeInfo nodeInfo, AlertRule alertRule) {
    JSONObject jsonObject = JSONObject.parseObject(JSONObject.toJSONString(nodeInfo));
    String alertKey = alertRule.getRuleKey();
    double alertValue = alertRule.getRuleValue();
    String nodeInfoField = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, alertKey);
    Double actualVal = jsonObject.getDouble(nodeInfoField);
    if (actualVal == null) {
        return false;
    }
    int compareType = alertRule.getCompareType();
    return compare(alertValue, actualVal, compareType);
}
 
Example 9
Source File: Utils.java    From Tangram-Android with MIT License 5 votes vote down vote up
public static Double getJsonDoubleValue(JSONObject json, String key) {
    Double tmp = json.getDouble(key);
    if (tmp == null) {
        return Double.NaN;
    } else {
        return tmp;
    }
}
 
Example 10
Source File: SOAResParseUtil.java    From AsuraFramework with Apache License 2.0 3 votes vote down vote up
/**
 * 根据key获取返回对象data中的double(只是第一层key),需要soa响应状态码是0
 *
 * @param result
 * @param key
 * @return
 * @author xuxiao
 * @created 2014年5月7日 下午6:00:25
 */
public static Double getDoubleFromDataByKey(final String result, final String key) {
    final JSONObject data = getDataObj(result);
    if (null != data) {
        return data.getDouble(key);
    } else {
        return null;
    }
}
 
Example 11
Source File: LocationIPO.java    From yue-library with Apache License 2.0 2 votes vote down vote up
/**
 * 将经纬度参数转换为位置对象
 * <p>
 * {@linkplain JSONObject} 转 {@linkplain LocationIPO}
 * @param location 标准的经纬度JSON对象,包含的key有("lng", "lat")
 * @return 经纬度对象
 */
public static LocationIPO toLocationIPO(JSONObject location) {
	double lng = location.getDouble("lng");
	double lat = location.getDouble("lat");
	return LocationIPO.builder().lng(lng).lat(lat).build();
}