Android 如何查看JSON数组以编辑视图
我是机器人乞丐。 我很困惑。因为我不知道如何在编辑视图中将JSON转换为视图(例如)。 许多人只是在原木上观看 这是我的JSON文件Android 如何查看JSON数组以编辑视图,android,json,Android,Json,我是机器人乞丐。 我很困惑。因为我不知道如何在编辑视图中将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
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);
}
EditText txt1=(EditText)findViewById(R.id.Text1);
RestClient=新的RestClient(“http://192.168.2.79/restserver/index.php/api/example/users");
//客户。AddParam(“id”,“1”)//参数
AddParam(“格式”、“json”)//参数格式
客户端.AddHeader(“GData版本”,“2”)//标题
试试{
client.Execute(RequestMethod.GET);
}捕获(例外e){
e、 printStackTrace();
}
字符串响应=client.getResponse();
Log.i(“respon”,响应);
//makeText(这是“json:+response,1.show()”;
//创建json创建
试一试{
JSONObject json=新的JSONObject(响应);
Log.i(“respon”,“\n”+json.toString()+”\n”);
//Log.i(“respon”,“\n”+json.t
JSONArray nameArray=json.names();
JSONArray valArray=json.toJSONArray(nameArray);
//试试1
JSONObject object=(JSONObject)新的JSONTokener(response).nextValue();
String[]id=新字符串[valArray.length()];
字符串[]名称=新字符串[valArray.length()];
字符串Id、名称;
对于(inti=0;i我认为您无法从JSON获取数据,请使用以下代码
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost("LINK");
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
StatusLine statusLine = response.getStatusLine();
int statuscode = statusLine.getStatusCode();
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(is, "UTF8"), 16);
stringBuilder = new StringBuilder();
stringBuilder.append(bufferedReader.readLine() + "\n");
String line = "0";
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line + "\n");
is.close();
Strign result = stringBuilder.toString();
JSONArray jArrayTemp = new JSONArray(result);
JSONObject json_data = null;
userID[i] = json_data.getString("UserID");
userName[i] = json_data.getString("UserName");
userLoginID[i] = json_data.getString("UserLoginID");
userPassword[i] = json_data.getString("UserPassword");
试试上面的代码
如果还可以借助下面的链接::
您到底想要什么?我想您想要在EditText视图上显示json的响应。如果是,那么它很简单,因为您可以在TextView上设置它,也可以在EditText上设置它。