gpt4 book ai didi

java - 如何将 googlesheet api 响应存储到 java 中的数组?

转载 作者:太空宇宙 更新时间:2023-11-04 09:24:19 24 4
gpt4 key购买 nike

    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=AIzaSyDJRy73ru1BSLFCb9nknUF8SlZd4LxwJAc
Response 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" ] ]}

我需要将响应数据填充到以下变量中。

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;

如果有人能帮助我,我将不胜感激。

最佳答案

您可以使用任何 JSON 到 Java 解码库将 JSON 转换为 Java 对象。检查options and examples

关于java - 如何将 googlesheet api 响应存储到 java 中的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57918123/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com