public class GeRen extends Activity {
private ArrayList s_list;
private TextView type,opendate,name,sex,enddate;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.geren);
initview();
//str為網絡請求到的json字符串
String str=this.getIntent().getStringExtra("key");
Log.e("TAG2", str);
Gson gson = new Gson();
Datas d = gson.fromJson(str, Datas.class);
setS_list(d.getResult());
// for(int i=0;i<s_list.size();i++){
// type.setText(s_list.get(i).getType());
// opendate.setText(s_list.get(i).getOpendate());
// name.setText(s_list.get(i).getName());
// sex.setText(s_list.get(i).getSex());
// enddate.setText(s_list.get(i).getEnddate());
// }
}
private void initview() {
type=(TextView) findViewById(R.id.type);
opendate=(TextView) findViewById(R.id.opendate);
name=(TextView) findViewById(R.id.name);
sex=(TextView) findViewById(R.id.sex);
enddate=(TextView) findViewById(R.id.enddate);
}
}
為什麼Datas d = gson.fromJson(str, Datas.class);為空 求大神解惑
返回數據錯了,應該是{"result_code":0,"result":[{"sex":"男","opendate":"2015-12-02","name":"李飛","type":"","enddate":"2016-12-02"}]}