第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將 googlesheet api 響應存儲到 java 中的數(shù)組?

如何將 googlesheet api 響應存儲到 java 中的數(shù)組?

富國滬深 2023-07-28 16:48:10
   public static String getsheetdata() throws IOException {    String name = null;    String email = null;    String phone = null;    String fin = null;    String address = null;    String car_registraion = null;    String question = null;    String pin = null;    String car_registraion_date = null;     String url = "https://sheets.googleapis.com/v4/spreadsheets/1BH-e3-XSZ9LjsQqELjZLpZbnB4DmIhrPy2VDAZsP9KM/values/lead!A2:J2?key=AIzaSyDJRy73ru1BSLFCb9nknUF8SlZd4LxwJAc";     URL obj = new URL(url);     HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();     // optional default is GET     con.setRequestMethod("GET");     //add request header     con.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.0.249.0 Safari/532.5");     int responseCode = con.getResponseCode();     System.out.println("\nSending 'GET' request to URL : " + url);     System.out.println("Response Code : " + responseCode);     BufferedReader in = new BufferedReader(             new InputStreamReader(con.getInputStream()));     String inputLine;     StringBuffer response = new StringBuffer();     while ((inputLine = in.readLine()) != null) {        response.append(inputLine);     }     in.close();     System.out.println(response.toString());     //Read JSON response and print     JSONObject myResponse = new JSONObject(response.toString());    return inputLine;}我收到以下回復Sending 'GET' request to URL : https://sheets.googleapis.com/v4/spreadsheets/1BH-e3-XSZ9LjsQqELjZLpZbnB4DmIhrPy2VDAZsP9KM/values/lead!A2:J2?key=AIzaSyDJRy73ru1BSLFCb9nknUF8SlZd4LxwJAcResponse Code : 200{  "range": "lead!A2:J2",  "majorDimension": "ROWS",  "values": [    [      "Lead Data Set 1 -  Normal FOC Lead",      "Bhupendra",      "bhupendra+283273@abc.com",      "2389432432",      "90909892098988771",      "Street123, Berlin",      "1289243424321",      "no comments",      "10115",      "12 / 12 / 2017"    ]  ]}我需要將響應數(shù)據(jù)填充到以下變量中。
查看完整描述

3 回答

?
慕妹3146593

TA貢獻1820條經(jīng)驗 獲得超9個贊

您可以嘗試(使用org.json):


? ? ?JSONObject myResponse = new JSONObject(response.toString());

? ? ?JSONArray jsonArr = (JSONArray) myResponse.get("values");

? ? ?JSONArray requiredValues = jsonArr.getJSONArray(0);

? ? ?String[] values = new String[requiredValues.length()];


? ? ?for (int i = 0; i < requiredValues.length(); i++) {

? ? ? ? values[i] = requiredValues.getString(i);

? ? ?}

現(xiàn)在"values"響應的部分將存儲在String[] values


? ? for (int j = 0; j < values.length; j++) {

? ? ? ? ?System.out.println(values[j]);

? ? }

這將打印 Lead Data Set 1 -? Normal FOC Lead

Bhupendra

bhupendra+283273@abc.com

2389432432

90909892098988771

Street123, Berlin

1289243424321

no comments

10115

12 / 12 / 2017


您可以相應地分配它。希望能幫助到你。


查看完整回答
反對 回復 2023-07-28
?
MYYA

TA貢獻1868條經(jīng)驗 獲得超4個贊

創(chuàng)建JSONObject您獲取的響應字符串,然后從as中提取values字段,然后遍歷該 JSONArray 以獲取對象列表。JSONObjectJSONArray



查看完整回答
反對 回復 2023-07-28
?
瀟湘沐

TA貢獻1816條經(jīng)驗 獲得超6個贊

您可以使用任何 JSON 到 Java 解組庫將 JSON 轉(zhuǎn)換為 Java 對象。檢查選項和示例


查看完整回答
反對 回復 2023-07-28
  • 3 回答
  • 0 關(guān)注
  • 198 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號