JSON parsing using Gson for Java

前端 未结 11 2292
青春惊慌失措
青春惊慌失措 2020-11-22 04:57

I would like to parse data from JSON which is of type String. I am using Google Gson.

I have:

jsonLine = \"
{
 \"data\": {
  \"translati         


        
11条回答
  •  悲&欢浪女
    2020-11-22 05:24

    You can use a JsonPath query to extract the value. And with JsonSurfer which is backed by Gson, your problem can be solved by simply two line of code!

        JsonSurfer jsonSurfer = JsonSurfer.gson();
        String result = jsonSurfer.collectOne(jsonLine, String.class, "$.data.translations[0].translatedText");
    

提交回复
热议问题