简体   繁体   English

如何从 java 中的字符串中提取双精度值

[英]How to extract double value from a string in java

Below is total string i have but i want to extract 31.0, could someone help on this.下面是我拥有的全部字符串,但我想提取 31.0,有人可以帮忙吗?

String Inseam = {"value":"30inch"-33inch" Shorts","key":"31.0"} String Inseam = {"value":"30inch"-33inch" 短裤","key":"31.0"}

I need 31.0 as an output to use the value some where我需要 31.0 作为 output 才能在某些地方使用该值

<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path</artifactId>
    <version>2.4.0</version>
</dependency>
JsonPath.parse(Inseam).read("$.key");

Full example:完整示例:

    public static void main(String[] args) {
        String inseam = "{\"value\":\"30inch\", \"key\":\"31.0\"}";
        String keyValue = JsonPath.parse(inseam).read("$.key");
        System.out.println(keyValue);
    }

Output: Output:

31.0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM