android - 如何在android上使用intent putExtra JsonObject?

标签 android android-intent android-json

<分区>

如何使用putExtra获取JsonObject?我想获取 JSON 文本以显示另一个 Activity 。

 @Override
 protected String doInBackground(Void... v) {

    HashMap<String, String> params = new HashMap<>();

    params.put(KEY_MEMBER_ID, memberId);
    params.put(KEY_PWD, pwd);

    JSONParser jParser = new JSONParser();

    JSONObject json = jParser.sendPostRequest(GlobalVariabel.URL_LOGIN_MEMBER, params);
    System.out.println("URL :######### "+GlobalVariabel.URL_LOGIN_MEMBER);

    try {
        status = json.getString("STATUS");

        System.out.println("STATUSSSSSSSSSSSSSSSSSS : " + status);
        System.out.println(json);

        JSONObject jObj = json.getJSONObject("PROFILE");
        if (jObj != null) {
            user_id = jObj.getString("USER_ID");
            profile_url = jObj.getString("PROFILE_URL");
            date_joined = jObj.getString("DATE_JOINED");
            phone_type = jObj.getString("PHONE_TYPE");
            email = jObj.getString("EMAIL");
            name = jObj.getString("NAME");
        }

        } catch (JSONException e) {
            e.printStackTrace();
        }
            return null;
        }

我想获取 JsonObject 电子邮件和名称,将 intent.putExtra 用于另一个 Activity 。

Intent intent = new Intent(getActivity(), MainActivity.class);
                    intent.putExtra(".... ", ....);
                    //intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    startActivity(intent);

最佳答案

用于发送json

Intent intent = new Intent(getActivity(), MainActivity.class);
                intent.putExtra("json", jsonObject.toString());
                startActivity(intent);

用于检索

       if(getIntent().hasExtra("json")) { 
       JsonObject mJsonObject = new JsonObject(getIntent().getStringExtra("json"));
    }

关于android - 如何在android上使用intent putExtra JsonObject?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40760337/

相关文章:

android - 是否可以在 Google+ API 中阅读所有传入的互动帖子?

Android:没有收到额外的 Intent ID

android - 对 FCM 服务器的 POST-ing JSON 请求不起作用

android - 如何从 JSONParser 类获取字符串变量的值?

android - 无法使用 Volley 将 JSONArray 转换为 JSONObject

java - 自定义卡片 View 形状

android - 如何从服务器读取pdf内容并保存在文件中?

android - 这个Android Studio项目的build.gradle中声明了哪些第三方依赖?

android,RESULT_OK 强制 Intent.ACTION_VIEW

android - 在不丢失数据的情况下处理屏幕旋转 - Android