我是 flutter 新手,正在使用 json。当我使用以下命令解码从服务器获得的响应时,json.decode()有时会出现以下错误
flutter: FormatException: Unexpected character (at character 21)
Run Code Online (Sandbox Code Playgroud)
有时它工作得很好。
这是我的代码
try {
Map<String, dynamic> map = new Map<String, dynamic>.from(
json.decode(contents));
if (map["CompletedJobPackages"] != null) {
DataStream.compleatedJobspackage =
DataStream.parseCompletedJobs(map["CompletedJobPackages"]);
print(map["CompletedJobPackages"]);
compleatedJobs = DataStream.compleatedJobspackage;
}
CompletedJobloaded = true;
}
catch(e){
print(e);
ToastUtils.showCustomToast(context, "An Error Occured. Try Again !", false);
}
Run Code Online (Sandbox Code Playgroud)
这是我要解码的对象
{
"CompletedJob": {
"CompletedJobID": 7,
"DriverID": 34,
"JobNumber": "80252C20",
"TraderID": 7,
"TripType": "Two Way",
"CargoType": "wd",
"CargoWeight": 230,
"LoadingPlace": "dc",
"UnloadingPlace": "sd",
"LoadingDate": "2020-05-25",
"LoadingTime": "12:59:00", …Run Code Online (Sandbox Code Playgroud) 当我尝试发布请求时,我得到
[VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: HandshakeException: Handshake error in client (OS Error:
CERTIFICATE_VERIFY_FAILED: ok(handshake.cc:354))
Run Code Online (Sandbox Code Playgroud)
我的代码(示例中提供)
Future login() async {
final request = {
"j_username": "user1",
"j_password": "pass1",
};
final response = await _dio.post('/itim/restlogin/login.jsp', data: request);
//get cooking from response
final cookies = response.headers.map['set-cookie'];
if (cookies.isNotEmpty && cookies.length == 2) {
final authToken = cookies[1].split(';')[0]; //it depends on how your server sending cookie
//save this authToken in local storage, and pass in further api calls.
aToken = authToken;
print("authToken");
//saving this to …Run Code Online (Sandbox Code Playgroud)