根据我显示的代码示例,responseJson返回FirstName的值。我想从responseJson中获取该值,因为我想将其传递给下一个活动。任何帮助将不胜感激。

@Override
        protected void onPostExecute(JSONObject result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);

            String myResJson;
            try {

                myResJson = responseJson.getString("Status");
                String test = myResJson;
                if (test.equals("200")) {
                    Intent intent = new Intent(contxt, ActivityMenu.class);

                    intent.putExtra("FirstName", firstname);
                    contxt.startActivity(intent);
                } else {
                    Toast.makeText(contxt,
                            "Login Error, invalid Email or Password", Toast.LENGTH_SHORT)
                            .show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }


这是我的responseJson值{"LastName":"A","UserID":"1","Status":"200","FirstName":"P"}

最佳答案

更改

intent.putExtra("FirstName", firstname);




intent.putExtra("FirstName", responseJson.getString("FirstName"));


要么

firstname=responseJson.getString("FirstName");

if(firstname!=null)
    intent.putExtra("FirstName", firstname);

09-27 18:16