JSON parsing using Gson for Java

前端 未结 11 2504
青春惊慌失措
青春惊慌失措 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:20

    You can create corresponding java classes for the json objects. The integer, string values can be mapped as is. Json can be parsed like this-

    Gson gson = new GsonBuilder().create(); 
    Response r = gson.fromJson(jsonString, Response.class);
    

    Here is an example- http://rowsandcolumns.blogspot.com/2013/02/url-encode-http-get-solr-request-and.html

提交回复
热议问题