简体   繁体   中英

How to get whole okhttp3 json response and print data?

I'm trying to get account information from site. I am not sure even how to do that. Am using okhttp3. I would like to retrieve the whole json object and print it out to see the data. I'd liek to see the whole object first but also retrieve only pieces too. am told to make use GET using this

app.get("/account", async (req, res) => {
  console.log(">>>Retrieving");
    const account = await stripe.accounts.retrieve(
      'acct_1234'
    );
});

Then should get object like this

{
  "id": "acct_1234",
  "object": "account",
  "business_profile": {
    "mcc": null,
    "name": null,
    "product_description": null,
    "support_address": null,
    "support_email": null,
    "support_phone": null,
    "support_url": null,
    "url": null
  },
  "business_type": null,
  "capabilities": {
    "card_payments": "active",
    "transfers": "active"
  },
  "charges_enabled": false,
  "country": "CA",
  "created": 1599337777,
  "default_currency": "cad",
  "details_submitted": false,
  "email": "email@gmail.com",
  "external_accounts": {
    "object": "list",
    "data": [],
    "has_more": false,
    "url": "/v1/accounts/acct_1234/external_accounts"
  },
  "metadata": {},
  "payouts_enabled": false,
  "requirements": {
    "current_deadline": null,
    "currently_due": [
      "business_profile.product_description",
      "business_profile.support_phone",
      "business_profile.url",
      "external_account",
      "tos_acceptance.date",
      "tos_acceptance.ip"
    ],
    "disabled_reason": "requirements.past_due",
    "errors": [],
    "eventually_due": [
      "business_profile.product_description",
      "business_profile.support_phone",
      "business_profile.url",
      "external_account",
      "tos_acceptance.date",
      "tos_acceptance.ip"
    ],
    "past_due": [],
    "pending_verification": []
  },
  "settings": {
    "bacs_debit_payments": {},
    "branding": {
      "icon": null,
      "logo": null,
      "primary_color": null,
      "secondary_color": null
    },
    "card_payments": {
      "decline_on": {
        "avs_failure": false,
        "cvc_failure": true
      },
      "statement_descriptor_prefix": null
    },
    "dashboard": {
      "display_name": null,
      "timezone": "America/Toronto"
    },
    "payments": {
      "statement_descriptor": "",
      "statement_descriptor_kana": null,
      "statement_descriptor_kanji": null
    },
    "payouts": {
      "debit_negative_balances": true,
      "schedule": {
        "delay_days": 7,
        "interval": "daily"
      },
      "statement_descriptor": null
    }
  },
  "tos_acceptance": {
    "date": null,
    "ip": null,
    "user_agent": null
  },
  "type": "custom"
}

Am using Stripe Api here >>>https://stripe.com/docs/api/accounts/create I've looked around but am not really understanding, am pretty new at using nodejs and okhttp3. Any advice helps. Thank you

I figured it all out. First i had to change the nodejs to\\

app.get("/account", async (req, res) => {
  console.log(">>>Retrieving");
    res.json(await stripe.accounts.retrieve(
      'acct_1234'
    ));
});

And the http request to display all the data and specific values

    public void sendGetRequest(String url){

        OkHttpClient.Builder builder = new OkHttpClient.Builder();

        builder.connectTimeout(30, TimeUnit.SECONDS);
        builder.readTimeout(30, TimeUnit.SECONDS);
        builder.writeTimeout(30, TimeUnit.SECONDS);

        httpClient = builder.build();

        Request request = new Request.Builder().url(url).build();

        try (Response response = httpClient.newCall(request).execute()) {
            String responseBody = response.body().string();
            Gson gson = new GsonBuilder().setPrettyPrinting().create();
            String perfectJSON = gson.toJson(JsonParser.parseString(responseBody));

            JSONObject json = new JSONObject(perfectJSON);

            JSONObject business = json.getJSONObject("business_profile");
            String phone = business.getString("support_phone");
            String id = json.getString("id");

            this.displayAlert(id+" > "+phone,perfectJSON);

        }catch (Exception e){
            e.printStackTrace();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM