如何从Login Api获取Login Layout页面的响应?

时间:2011-10-21 13:41:44

标签: android json parsing

我从Api解析json提要并且它包含一些提要,在我的登录页面中我需要从提要输入两个字段,我需要得到一个响应,无论提要是否正确..如果不是我需要注册..我将如何保存我的Feed中的登录详细信息以及如何从Feed中获取响应

1 个答案:

答案 0 :(得分:1)

这样的东西?

private void getJSON()
{
/* [...] code inside the function that receives the response */ 
    try
    {
        JSONObject jsonResponse = new JSONObject(response);
        String status = jsonResponse.getString("status");
        if(status.compareTo("success") != 0)
            throw new JSONException(status);
        if(!checkEmailPassword( jResponse.getString("email"), jResponse.getString("password") ))
            Toast.makeText(this, "Invalid user", Toast.LENGTH_SHORT).show();
    }catch (JSONException e)
    {
        Toast.makeText(this, "Bad response", Toast.LENGTH_SHORT).show();
        e.printStackTrace();
    }
}   

private boolean checkEmailPassword(String email, String password)
{
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
    boolean verified =  false;
    if( preferences.getString("email", "").compareTo(email) == 0
     && preferences.getString("password", "").compareTo(password) == 0 )
    {
        verified = true;
    }
    return verified;
}