我有一个JSON是String如何在ListView中填充JSON数据,任何人都可以帮我处理代码片段吗?
String json="[{"Id":"30","Name":"Accident And Emergency Care"},{"Id":"2","Name":"Anesthesiology And Pain Management "},{"Id":"3","Name":"Cardiology And Cardiothoracic Surgery"},{"Id":"32","Name":"Clinical Nutrition And Dietetics"},{"Id":"33","Name":"Critical Care"},{"Id":"34","Name":"Day Care"},{"Id":"9","Name":"Dental Surgery"},{"Id":"19","Name":"Dermatology And Cosmetology"},{"Id":"23","Name":"Dialysis"},{"Id":"6","Name":"E.N.T"},{"Id":"10","Name":"Endocrinology"},{"Id":"20","Name":"Eye"},{"Id":"18","Name":"Gastroenterology"},{"Id":"11","Name":"General Surgery"},{"Id":"39","Name":"Maxillo Facial"},{"Id":"12","Name":"Medicine"},{"Id":"13","Name":"Nephrology"},{"Id":"26","Name":"Neurology"},{"Id":"14","Name":"Neurosurgery"},{"Id":"15","Name":"Obstetrics and Gynaecology"},{"Id":"29","Name":"Oncology"},{"Id":"7","Name":"Orthopedics"},{"Id":"36","Name":"Pathology And Blood Bank"},{"Id":"16","Name":"Pediatrics And Neonatology"},{"Id":"37","Name":"Plastic And Reconstructive Surgery"},{"Id":"17","Name":"Psychiatry"},{"Id":"25","Name":"Pulmonology"},{"Id":"38","Name":"Radiology"},{"Id":"24","Name":"Rheumatology"},{"Id":"5","Name":"Urology"}]}";
答案 0 :(得分:0)
class ModelClass {
public String id;
public String name;
}
Gson gson = new Gson();
gson.fromJson(jsonString, ModelClass[].class);
在app level build.gradle中:compile 'com.squareup.retrofit2:converter-gson:2.0.2'