這是我doInBackground如何設置從php腳本接收標記的字符串變量?
protected Integer doInBackground(String... args) {
try {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", Username));
params.add(new BasicNameValuePair("password", Password));
Log.d("request!", "starting");
JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST", params);
Log.d("Login attempt", json.toString());
success = json.getInt(TAG_SUCCESS);
res = json.getString(TAG_MESSAGE);
loginposition = json.getJSONArray(TAG_POSTS);
for (int i = 0; i < loginposition.length(); i++) {
JSONObject c = loginposition.getJSONObject(i);
Position = c.getString(TAG_POSITION);
}
} catch (JSONException e) {
Log.e(TAG, "JSON error", e);
success = Integer.valueOf(0);
}
return success;
}
我宣佈調整量爲String Position
,我不知道爲什麼我的Android JSON說我的成功不是1或爲空。即使我的標籤後。
這是我的logcat
12-13 15:52:09.830: D/request!(27146): starting
12-13 15:52:13.139: D/Login attempt(27146): {"posts":["user"],"message":"Login Successful!","success":1}
12-13 15:52:13.149: E/(27146): JSON error
12-13 15:52:13.149: E/(27146): org.json.JSONException: Value user at 0 of type java.lang.String cannot be converted to JSONObject
12-13 15:52:13.149: E/(27146): at org.json.JSON.typeMismatch(JSON.java:96)
12-13 15:52:13.149: E/(27146): at org.json.JSONArray.getJSONObject(JSONArray.java:484)
12-13 15:52:13.149: E/(27146): at com.pmss.Login$AttemptLogin.doInBackground(Login.java:157)
12-13 15:52:13.149: E/(27146): at com.pmss.Login$AttemptLogin.doInBackground(Login.java:1)
12-13 15:52:13.149: E/(27146): at android.os.AsyncTask$2.call(AsyncTask.java:185)
12-13 15:52:13.149: E/(27146): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
12-13 15:52:13.149: E/(27146): at java.util.concurrent.FutureTask.run(FutureTask.java:138)
12-13 15:52:13.149: E/(27146): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
12-13 15:52:13.149: E/(27146): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
12-13 15:52:13.149: E/(27146): at java.lang.Thread.run(Thread.java:1019)
12-13 15:52:13.149: D/Login Failure!(27146): res: Login Successful!
是JSONArray類型的登錄位置?另外,什麼是位置? – Melquiades
loginposition是JSONArray類型是和'Position'是一個字符串變量,負責保存字符串像我的數據庫中的'user'和'staff' –