0
我試圖解析此JSON通過我的客戶的API捕獲:JSON解析與庫GSON在Java中
[
{
"pagination": {
"page": 7,
"total_pages": 11,
"entries": 100,
"total_entries": 1007
},
"logical_numbers": [
{
"logical_number": {
"id": 50095,
"number": "524103650",
"app_version_ids": [
1427,
1230,
847
],
"created_by": 1510,
"created_via": "interface",
"group_id": 526,
"created_at": "2016-03-21T15:54:30.670-03:00",
"updated_at": "2016-03-21T15:54:30.682-03:00"
}
},
{
"logical_number": {
"id": 44593,
"number": "524103627",
"app_version_ids": [
1427,
1230,
847
],
"created_by": 1510,
"created_via": "interface",
"group_id": 526,
"created_at": "2016-02-26T10:02:20.561-03:00",
"updated_at": "2016-02-26T10:02:20.608-03:00"
}
}
]
}
]
下面是我對這項工作創建的類:
import java.io.FileReader;
import java.util.ArrayList;
import com.google.gson.Gson;
public class Test {
public static void main(String[] args) {
Gson gson = new Gson();
Pagination[] pagination = gson.fromJson(new FileReader("input1.json"), Pagination[].class);
System.out.println(gson.toJson(pagination));
}
}
class Pagination {
Long page;
Long total_pages;
Long entries;
Long total_entries;
ArrayList<LogicalNumbers> logicals;
}
class LogicalNumbers {
int id;
String number;
ArrayList<String> app_version_ids = new ArrayList<>();
String created_by;
String created_via;
String group_id;
String created_at;
String updated_at;
}
當我運行這段代碼,我得到以下結果:
[{}]
我在解析中沒有成功。有誰能夠幫助我?
謝謝。
工作!謝謝! –
歡迎您,請不要忘記投票或接受答案,如果帖子解決您的問題 –