GSON을 사용하여 JSON Object로 변환해야하는 List가 있습니다. 내 JSON 개체에 JSON 배열이 있습니다. 지금 현재로GSON을 사용하여 List를 JSON 객체로 변환하는 방법은 무엇입니까?
public void marshal(Object response) {
List<DataResponse.ClientResponse> clientResponse = ((DataResponse) response).getClientResponse();
// now how do I convert clientResponse list to JSON Object which has JSON Array in it using GSON?
// String jsonObject = ??
}
, 난 단지 목록에 두 개의 항목이 - - 아래
public class DataResponse {
private List<ClientResponse> apps;
// getters and setters
public static class ClientResponse {
private double mean;
private double deviation;
private int code;
private String pack;
private int version;
// getters and setters
}
}
내가 JSON의 그것에 배열을 가지고 JSON 개체 내 목록을 변환 할 필요가있는 내 코드입니다 그래서 이런 JSON 객체가 필요합니다. -
{
"apps":[
{
"mean":1.2,
"deviation":1.3
"code":100,
"pack":"hello",
"version":1
},
{
"mean":1.5,
"deviation":1.1
"code":200,
"pack":"world",
"version":2
}
]
}
가장 좋은 방법은 무엇입니까?
표시 한 JSON은 JSON 배열이 아니며 JSON 객체입니다. –
죄송합니다. 예, JSON 개체입니다. 질문에 대해 다시 말해 보겠습니다. – AKIWEB