Android Web服务,响应不正确

时间:2016-01-24 15:06:46

标签: android web-services

我需要向网址/controller/action发出请求。我没有得到以下代码的预期响应:

public class MainActivity extends Activity {

    List<String> responseList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AutoCompleteTextView auto1 = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);



        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_expandable_list_item_2, responseList);
        auto1.setAdapter(adapter);

    }

    private void handleResponse(JSONObject serverResponse) {
        int success = 0;
        try {
            success = serverResponse.getInt(Responce.TAG_SUCCESS);
            if (success == 1) {
                progress.dismiss();
                //after login we want to store user's id into shared preferences
                /*SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                SharedPreferences.Editor editor = sharedPreferences.edit();
                editor.putString("cust_id", serverResponse.getString("CustomerId"));
                editor.commit();*/

                Toast.makeText(MainActivity.this, serverResponse.getString((Responce.TAG_MESSAGE)), Toast.LENGTH_LONG).show();

            } else {
                progress.dismiss();
                //Util.log(TAG, serverResponse.getString(Responce.TAG_ERROR));
                Toast.makeText(MainActivity.this, serverResponse.getString(Responce.TAG_MESSAGE), Toast.LENGTH_LONG).show();
            }
        } catch (JSONException e) {
            // Util.log(TAG, e.getMessage());
        }

    }

    @Override
    public void onComplete(JSONObject serverResponse, int RESPONSE_IDENTIFIER_FLAG) throws JSONException {
        switch (RESPONSE_IDENTIFIER_FLAG) {
            case 1:
                handleResponse(serverResponse);
                break;
            default:
        }

    }

}

0 个答案:

没有答案