可以从服务器更改数据? 你必须从PHP服务器数据获取{"project_data": [{"id":"14","name":"JOHN","short_name":"JH" }]}
然后对JSON对象进行解码。public class MainActivity extends Activity {
TextView txtView;
TextView txtView1;
int i=0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtView = (TextView) findViewById(R.id.txtView);
txtView1 = (TextView) findViewById(R.id.txtView1);
//String job ="'project_data': [null,null,{'id': '14','name': 'JOHN','short_name': 'JH', }]";//bad data
String job ="{'project_data': [{'id': '14','name': 'JOHN','short_name': 'JH' }]}";
txtView.setText(job);
try{
String s ="" ;
JSONObject jsnobject = new JSONObject(job);
JSONArray jsonArray = jsnobject.getJSONArray("project_data");
for (int i = 0; i
JSONObject explrObject = jsonArray.getJSONObject(i);
s= s+"name:" + explrObject.getString("name")+"n" +
"short_name:"+ explrObject.getString("short_name") +"n";
}
txtView1.setText(s);
}catch(Exception e){
txtView.setText("error 3"+i+""+ e.toString());
}
}
}