How to convert List to a JSON Object using GSON?

前端 未结 4 442
你的背包
你的背包 2020-12-05 17:08

I have a List which I need to convert into JSON Object using GSON. My JSON Object has JSON Array in it.

public class DataResponse {

    private List

        
4条回答
  •  醉酒成梦
    2020-12-05 18:05

    If response in your marshal method is a DataResponse, then that's what you should be serializing.

    Gson gson = new Gson();
    gson.toJson(response);
    

    That will give you the JSON output you are looking for.

提交回复
热议问题