【发布时间】:2020-05-10 18:52:05
【问题描述】:
我从 google 表格中获取数据列表到我的 android 应用程序中。 Google 脚本运行正常,测试运行也提供了正确的输出。但是,在 android 应用程序中接收到的 JSON 数据看起来像垃圾。这是我的android端代码。我正在使用 Volley:
private fun getList() {
val stringRequest = StringRequest(
Request.Method.GET, "https://docs.google.com/spreadsheets/d/***********/edit#gid=0",
Response.Listener<String> { response ->
Log.d("MyMessage", response)
parseItems(response)
},
Response.ErrorListener { responseEr -> }
)
val socketTimeOut = 500000
val policy = DefaultRetryPolicy(socketTimeOut, 0, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)
stringRequest.retryPolicy = policy
val queue = Volley.newRequestQueue(this)
queue.add(stringRequest)
}
google appscript如下:
function doGet(e){
var action = e.parameter.action;
if(action == 'getList'){
return getList(e);
}
}
function getList(e){
var records={};
var sheet = ss.getSheetByName('*****');
var rows = sheet.getDataRange().getValues();
data = [];
for (var r = 1; r < 10; r++) {
record = rows[r][1];
data.push(record);
}
records.items = data;
var result=JSON.stringify(records);
return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
}
当我使用提供的链接测试 appCode 脚本时,我得到的正确列表如下:
{"items":["****","****","****",........,"*****"]}
但android应用中的响应日志提供了以下输出:
....
我在这里做错了什么
【问题讨论】:
-
提供详细信息,如标记google-apps-script-web-application 的“使用指南”中所写,例如网络应用程序是如何发布的?
标签: android kotlin google-apps-script android-volley