格式异常:意外字符(字符 1 处)



>我正在Flutter中制作工作表,人们将在其中输入所有信息,该信息将传递给Google工作表。 但是当我尝试传递数据时,我收到以下错误:

I/flutter (23770): FormatException: Unexpected character (at character 1)
I/flutter (23770): <!DOCTYPE html><html><head><link rel="shortcut icon" href="//ssl.gstatic.co...
I/flutter (23770): ^

我的 API 调用代码如下:

import 'package:fooddeliveryapp/model/Customer_Information.dart';
import 'package:http/http.dart' as http;
import 'dart:convert' as convert;
class InformationController {
final void Function(String) callback;
static const String URL =
"https://script.google.com/macros/s/AKfycbxuNeIu5cibZHs9sXM6vsl-X5Cf7muMP18xRiDCRXNDF--z0y8o/exec";
static const STATUS_SUCCESS = "SUCCESS";
InformationController(this.callback);
void submitCustomerInformation(
CustomerInformation customerInformation) async {
try {
await http.get(URL + customerInformation.toParams()).then((response) {
callback(convert.jsonDecode(response.body)['Status']);
}); 
} catch (e) {
print(e);
}
}
}

以下是我的电子表格脚本编辑器代码:

function doGet(request) {
var sheet=spreadsheetApp.openById("1UWt6IVRcebqErf4mjURKAY-_oC7dBMtbOx1CQ8cfW0Q");
var result={"status": "SUCCESS"};
try{
var Name=request.parameter.Name;
var PhoneNumber=request.parameter.PhoneNumber;
var Address=request.parameter.Address;
var rowData=sheet.appendRow([Name,PhoneNumber,Address]);
}catch(exc){

result={"Status":"FAILED","message":exc};
}
return ContentService
.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}

帮助将不胜感激,谢谢!!

问题:

doGet抛出一个引用错误,因为没有定义spreadsheetApp:这是一个错别字;应该是SpreadsheetApp,第一个字母大写。

因此,对 Web 应用的请求将返回错误页面,而不是预期的文本输出。

如果您尝试使用浏览器访问脚本 URL,您可以检查这是怎么回事。

溶液:

修正拼写错误,改为以这种方式打开电子表格:

var sheet = SpreadsheetApp.openById("1UWt6IVRcebqErf4mjURKAY-_oC7dBMtbOx1CQ8cfW0Q");

参考:

  • 班级电子表格应用程序

最新更新