-2
我可以通過JSON
檢索listview
中的數據,但我想顯示與用戶登錄相關的數據,因此我必須將用戶名發送到PHP
腳本。我不知道如何將用戶名發佈到PHP
腳本,然後從Web服務器獲得響應。Android JSON POST,然後回覆
private class GetFixture extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... arg) {
ServiceHandler serviceClient = new ServiceHandler();
Log.d("url: ", "> " + URL_ITEMS);
String json = serviceClient.makeServiceCall(URL_ITEMS,ServiceHandler.GET);
// print the json response in the log
Log.d("Get match fixture resps","> " + json);
if (json != null) {
try {
Log.d("try", "in the try");
JSONObject jsonObj = new JSONObject(json);
Log.d("jsonObject", "new json Object");
// Getting JSON Array node
matchFixture = jsonObj.getJSONArray(TAG_FIXTURE);
Log.d("json aray", "user point array");
int len = matchFixture.length();
Log.d("len", "get array length");
for (int i = 0; i < matchFixture.length(); i++) {
JSONObject c = matchFixture.getJSONObject(i);
String matchId = c.getString(TAG_MATCHID);
Log.d("matchId", matchId);
String teamA = c.getString(TAG_TEAMA);
Log.d("teamA", teamA);
String teamB = c.getString(TAG_TEAMB);
Log.d("teamB", teamB);
// hashmap for single match
HashMap<String, String> matchFixture = new HashMap<String, String>();
// adding each child node to HashMap key => value
matchFixture.put(TAG_MATCHID, matchId);
matchFixture.put(TAG_TEAMA, teamA);
matchFixture.put(TAG_TEAMB, teamB);
matchFixtureList.add(matchFixture);
}
}
catch (JSONException e) {
Log.d("catch", "in the catch");
e.printStackTrace();
}
} else {
Log.e("JSON Data", "Didn't receive any data from server!");
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
ListAdapter adapter = new SimpleAdapter(
Doctor_Names.this, matchFixtureList,
R.layout.list_item, new String[] {
TAG_MATCHID, TAG_TEAMA,TAG_TEAMB
}
, new int[] {
R.id.teamA,R.id.name,
R.id.teamB
}
);
setListAdapter(adapter);
}
先生這段代碼完全告訴我從該服務器的所有數據,但我想一些具體的數據,如我要顯示與誰是登錄所以,我要的用戶名傳遞給PHP
個人數據腳本,所以不要有想法POST
的基礎上的任何東西的網絡,而我可以過濾數據
你要問一個更具體的問題,你有什麼到目前爲止和你在哪裏卡住了? – cyroxis
重複[執行獲取/從服務器發佈的JSON響應在Android](http://stackoverflow.com/questions/31305631/performing-get-post-from-server-for-json-response-in-android)和數十人。你甚至搜索過嗎? – 323go
我添加了我的帖子先生 –