0
我是begginer开发android。 我很困惑。因为我不知道要将JSON转换为在编辑视图中查看(例如)。在Log上有很多公正的视角。如何查看JSON数组来编辑查看
这一点,我的JSON文件
EditText txt1 = (EditText) findViewById(R.id.Text1);
RestClient client = new RestClient("http://192.168.2.79/restserver/index.php/api/example/users");
//client.AddParam("id", "1"); //parameter
client.AddParam("format", "json"); //parameter format
client.AddHeader("GData-Version", "2"); //header
try {
client.Execute(RequestMethod.GET);
} catch (Exception e) {
e.printStackTrace();
}
String response = client.getResponse();
Log.i("respon",response);
//Toast.makeText(this, "json : "+ response, 1).show();
//create json creation
try {
JSONObject json = new JSONObject(response);
Log.i("respon","<jsonobject>\n"+json.toString()+"\n</json>");
//Log.i("respon","<jsonobject>\n"+json.t
JSONArray nameArray = json.names();
JSONArray valArray = json.toJSONArray(nameArray);
//try 1
JSONObject object = (JSONObject) new JSONTokener(response).nextValue();
String[] id = new String[valArray.length()];
String[] name = new String[valArray.length()];
String Id,Name;
for(int i=0;i<valArray.length();i++) {
Log.i("respon","<jsonname"+i+">\n"+nameArray.getString(i)+"\n</jsonname"+i+">\n"
+"<jsonvalue"+i+"\n"+valArray.getString(i)+"\n</jsonvalue"+i+">");
//coba
JSONObject obj = valArray.getJSONObject(i);
id[i] = obj.getString("id");
name[i] = obj.getString("name");
//wanna show at EditView, ect (but I can't)
Toast.makeText(this, "id : " + " ,name : ", 1).show();
txt1.setText("id : " + id + " ,name : "+name);
}
如何解决JSON来查看,不仅在日志中。而且还在对象(widget android)上。 thanx很多家伙....
正是你想要的链接如下::也的帮助?我想你想在EditText View上显示json的响应。如果是,那么它的简单,你设置它在TextView上,你也可以在EditText上设置它。 – 2012-01-16 09:40:10