我已經開始在android開發工作,所以我要求從JSON格式的數據庫中的數據,我得到像「{」用戶「的返回值:[{ CHILD_NAME「:」約翰「}]}」這裏是我的代碼,我使用得到顯示的響應:我想顯示從json對象的值在Android活動
公共類的歡迎延伸活動{
private static final String URL = "http://www.schools.weavearound.com/android_api/user_fetch.php";
private StringRequest request;
private RequestQueue requestQueue;
private Button log_out;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_activity);
// email = (EditText) findViewById(R.id.email);
final String strJson="";
final TextView testTextView = (TextView) findViewById(R.id.display);
requestQueue = Volley.newRequestQueue(this);
final TextView nameView = (TextView) findViewById(R.id.result_txt);
nameView.setText(getIntent().getExtras().getString("username"));
// fetch the db here
request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
//Log.e("tag", e.getMessage());
String data = "";
try {
JSONObject jsonObject = new JSONObject(response);
//Get the instance of JSONArray that contains JSONObjects
JSONArray jsonArray = jsonObject.optJSONArray("users");
//Iterate the jsonArray and print the info of JSONObjects
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
String name = jsonObject1.optString("child_name").toString();
data += "Node" + i + " : name= " + name +" \n ";
}
testTextView.setText(data);
} catch (JSONException e) {
e.printStackTrace();
}
}
},new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
}
}
,但沒有價值正在顯示在活動中。請幫助我。
能否請您詳細闡述更多關於這一點,在那裏,哪部分我想提出一個錯誤? – user2592029