简体   繁体   中英

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.

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

I need 31.0 as an output to use the value some where

<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:

31.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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