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

The following examples show how to use com.alibaba.fastjson.JSONObject#getFloat() . 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: MobileAction.java    From agent with MIT License 6 votes vote down vote up
private Point[] createStartAndEndPointInContainer(WebElement container, String startPoint, String endPoint) {
    Assert.notNull(container, "container不能为空");

    Rectangle containerRect = container.getRect();
    int containerHeight = containerRect.getHeight();
    int containerWidth = containerRect.getWidth();

    // 容器左上角坐标
    Point containerRectPoint = containerRect.getPoint();
    int containerLeftTopX = containerRectPoint.getX();
    int containerLeftTopY = containerRectPoint.getY();

    try {
        JSONObject _startPoint = JSONObject.parseObject(startPoint.trim());
        JSONObject _endPoint = JSONObject.parseObject(endPoint.trim());

        int startX = containerLeftTopX + (int) (_startPoint.getFloat("x") * containerWidth);
        int startY = containerLeftTopY + (int) (_startPoint.getFloat("y") * containerHeight);
        int endX = containerLeftTopX + (int) (_endPoint.getFloat("x") * containerWidth);
        int endY = containerLeftTopY + (int) (_endPoint.getFloat("y") * containerHeight);

        return new Point[]{new Point(startX, startY), new Point(endX, endY)};
    } catch (Exception e) {
        throw new IllegalArgumentException("point格式错误,正确格式示例: {x:0.5,y:0.5}");
    }
}
 
Example 2
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 Float formFloat(String jsonString, String key) {
    try {
        if (jsonString != null && jsonString.length() > 0) {
            JSONObject jsonObject = JSONObject.parseObject(jsonString);
            return jsonObject.getFloat(key);
        } else {
            return null;
        }
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 3
Source File: MobileAction.java    From agent with MIT License 5 votes vote down vote up
private Point createPoint(String point, Dimension window) {
    int screenWidth = window.width;
    int screenHeight = window.height;

    try {
        JSONObject _point = JSONObject.parseObject(point.trim());
        int x = (int) (_point.getFloat("x") * screenWidth);
        int y = (int) (_point.getFloat("y") * screenHeight);

        return new Point(x, y);
    } catch (Exception e) {
        throw new IllegalArgumentException(point + "格式错误, 正确格式示例: {x:0.5,y:0.5}");
    }
}
 
Example 4
Source File: JSONUtil.java    From easyweb-shiro with MIT License 5 votes vote down vote up
/**
 * 得到Float类型的值
 */
public static Float getFloat(String json, String key) {
    Float result = null;
    try {
        JSONObject jsonObject = JSON.parseObject(json);
        result = jsonObject.getFloat(key);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return result;
}
 
Example 5
Source File: Utils.java    From Tangram-Android with MIT License 5 votes vote down vote up
public static Float getJsonFloatValue(JSONObject json, String key) {
    Float tmp = json.getFloat(key);
    if (tmp == null) {
        return Float.NaN;
    } else {
        return tmp;
    }
}
 
Example 6
Source File: ActionController.java    From UIAutomatorWD with MIT License 5 votes vote down vote up
private static boolean pinch(JSONObject args) throws Exception {
    String elementId = args.getString("element");
    Element el;
    if (elementId == null) {
        el = elements.getElement("1");
    } else {
        el = elements.getElement(elementId);
    }
    String direction = args.getString("direction");
    float percent = args.getFloat("percent");
    int steps = args.getInteger("steps");
    return el.pinch(direction, percent, steps);
}
 
Example 7
Source File: SOAResParseUtil.java    From AsuraFramework with Apache License 2.0 3 votes vote down vote up
/**
 * 根据key获取返回对象data中的float(只是第一层key),需要soa响应状态码是0
 *
 * @param result
 * @param key
 * @return
 * @author xuxiao
 * @created 2014年5月7日 下午6:00:25
 */
public static Float getFloatFromDataByKey(final String result, final String key) {
    final JSONObject data = getDataObj(result);
    if (null != data) {
        return data.getFloat(key);
    } else {
        return null;
    }
}