我有这个json字符串:
{"work_completion_forms":
[
{
"id": "2a6aae87-af4f-4aa9-8e43-05af2be6d963",
"name": "File"
},
{
"id": "b6e35c72-026e-4ef0-8eff-36d040054a93",
"name": "Comment"
}
]
}
我如何解析它?
我试试这个:
Gson g = new Gson();
Parse p = g.fromJson(result, Parse.class);
String[] s = p.get_work_completion_forms();
for (int i = 0; i < s.length;i++){
Log.d(s[i], "lol");
}
public class Parse {
public String[] work_completion_forms;
public String[] get_work_completion_forms()
{
return work_completion_forms;
}
}
答案 0 :(得分:2)
String[] work_completion_forms
这是您的代码的问题。他们的work_completion_forms
类型不是String
,而是更复杂的东西。尝试那样
public class WorKCompletionForms {
private String id;
private String name;
// getters and setters
}
WokCompletionForms[] s = p.get_work_completion_forms();
for (int i = 0; i < s.length;i++){
Log.d("TAG", s[i].getId());
}