如何转换JSON,它是String和Array的组合,请建议如何使用代码执行此操作,假设我们有以下JSON
{"status":"true","results":[{"name":"Sudini "},{"name":"Bimal"}]}
答案 0 :(得分:1)
查看gson,一个google库,将java对象序列化/反序列化为json。
答案 1 :(得分:1)
答案 2 :(得分:1)
如果你在GSON中这样做:
public class Something{
@SerializedName("status")
private boolean status;
@SerializedName("results")
private List<Result> results;
// accessor and mutator
}
public class Result{
@SerializedName("name")
private String name;
// accessor and mutator
}
public class App {
public static void main(String[] args) {
Gson gson = new Gson();
String jsonString = // your json string
Something obj = (Something) gson.fromJson(jsonString, Something.class);
System.out.println(obj.getResults().get(1).getName());
}
}