无法从CustomRequest获取响应数据

时间:2016-01-06 14:40:13

标签: android json request response

我是这样回答SO:Volley JsonObjectRequest Post request not working

我无法从请求中获取响应数据。

我在我的android项目中创建了帮助类,现在尝试这样做:

RequestQueue requestQueue = Volley.newRequestQueue(this);
CustomRequest jsObjRequest = new CustomRequest(Method.POST, AppConfig.URL_LOGIN, datamap, this.RequestSuccessListener(), this.RequestErrorListener());
requestQueue.add(jsObjRequest);

这是我的requestSucessListener代码。问题是我不知道如何传递我从响应中收到的数据对象。

public void RequestSuccessListener(){

    JSONObject jObj = new JSONObject();
    //hideDialog();

    try {
        boolean error = jObj.getBoolean("error");

        // Check for error node in json
        if (!error) {
            // user successfully logged in
            // Create login session
            session.setLogin(true);

            // Now store the user in SQLite
            String uid = jObj.getString("uid");

            JSONObject user = jObj.getJSONObject("user");
            String name = user.getString("name");
            String email = user.getString("email");
            String userid = user.getString("user_id");
            // Inserting row in users table

            // Launch main activity

            //Intent intent = new Intent(LoginActivity.class,MainActivity.class);
            //startActivity(intent);
            //finish();
        } else {
            // Error in login. Get the error message
            String errorMsg = jObj.getString("error_msg");
            //Toast.makeText(getApplicationContext(),
            //      errorMsg, Toast.LENGTH_LONG).show();
        }
    } catch (JSONException e) {
        // JSON error
        e.printStackTrace();
        //Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

0 个答案:

没有答案