在 Java 中阅读 JSON 属性

Read JSON property in Java

当我从 java 调用 postAPI 时,我的速度低于 output。我想将 access_token 存储在一个变量中,但我做不到。在 javascript 我可以轻松做到,但在 Java 这对我来说变得越来越困难。任何人都可以帮助我吗?

{
    "access_token": "eyJ4NXQjUzI1NiI6IjZhYnBycWVsRl9ld3NEaW1HRy0wY0JpNVg2N09jQjkzTGNyN2Y4M3UzLXMiLCJ4NXQiOiJkdlhSRXBGdXpTenRMdGlMM2Vmbk1rbVo0Rk0iLCJraWQiOiJTSUdOSU5HX0tFWSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJpZGNzLW9kYS05NDE3ZjkzNTYwYjk0ZWI4YTJlMmE0YzlhYWM5YTNmZi10MF9BUFBJRCIsInVzZXIudGVuYW50Lm5hbWUiOiJpZGNzLTgyOTcyOTIxZTQyNjQxYjFiZjA4MTI4YzNkOTNhMTljIiwic3ViX21hcHBpbmdhdHRyIjoidXNlck5hbWUiLCJwcmltVGVuYW50Ijp0cnVlLCJpc3MiOiJodHRwczpcL1wvaWRlbnRpdHkub3JhY2xlY2xvdWQuY29tXC8iLCJ0b2tfdHlwZSI6IkFUIiwiY2xpZW50X2lkIjoiaWRjcy1vZGEtOTQxN2Y5MzU2MGI5NGViOGEyZTJhNGM5YWFjOWEzZmYtdDBfQVBQSUQiLCJjYV9ndWlkIjoiY2FjY3QtYzZkNjgxNDI5YzZiNGQyMTgzMzkwYWE2ZTczZGNmY2IiLCJhdWQiOiJodHRwczpcL1wvaWRjcy1vZGEtOTQxN2Y5MzU2MGI5NGViOGEyZTJhNGM5YWFjOWEzZmYtdDAuZGF0YS5kaWdpdGFsYXNzaXN0YW50Lm9jaS5vYy10ZXN0LmNvbSIsInN1Yl90eXBlIjoiY2xpZW50Iiwic2NvcGUiOiJcL2FwaVwvdjEiLCJjbGllbnRfdGVuYW50bmFtZSI6ImlkY3MtODI5NzI5MjFlNDI2NDFiMWJmMDgxMjhjM2Q5M2ExOWMiLCJleHAiOjE1OTMz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ZmU3LTQwZDMtODE4NS03OWQ1NWEyOGFjMmEifQ.fFtCsQmgrf_jhU_pxa03O8ddP-1vjvOz7ciTqMbY-efeFsH1M17dzA2IAUlKbbg0I-bHHmu-IGBVTCaNwTuR5BaogR4z6ZlN03ojLkvbfstMlLxDqSn51U2v-wXXmF_Y7dypfxGqaDevlrlzJmh3Ve7Bq9AY0jMlwhLlMxLjvcVXGpGoiZ7a96K94rHUSgDf3-rZIy6dkYpTGWOaDV61Xfh3_HO8n85wUHVyqIuVjaeAg-BBModl2kd7oWp93bz9s_PA57d2Pr8yrbq7zxMbCSZ6fT_52_QJ17bAADBMvboXc0dDo1E6M1DgbQSnW80NDkYC_UI2OGFz-_Vg4aaPXw\",\"token_type\":\"Bearer\",\"expires_in\":3600}";
    //assign your JSON String here
   JsonObject obj=Json.parse(data).asObject();
   String accessToken=obj.get("access_token").asString();
     System.out.println(accessToken);