我正在使用nodejs后端和flutter應用程式。我使用flutter http包來發送請求。我想通過請求來發送日期時間,所以我把它轉換成了字串。所以在node后端,這個資料不能被轉換為原始型別(如DateTime或int)。在flutter和node中處理JSON資料的最佳做法是什么。我想通過http請求發送資料(日期、字串、int),并在后端以正確的格式檢索它們。 這里是flutter的函式。這完全是將所有細節轉換為字串,但我無法在節點后臺檢索到原始格式。
Future<PlanDataInit> createItin(String?/span> name, String?/span> budget,
DateTime? startDate, DateTime? endDate) async {
final response = await http.post(
Uri.parse('http://localhost:3001/itinerary/createitin') 。
headers: <String, String> {
'Content-Type': 'application/json; charset=UTF-8',
},
body: jsonEncode(<String, String> {
"Name": name.toString(),
"startDate"/span>: startDate.toString(),
"endDate"/span>: endDate.toString(),
"initialBud": budget.toString()
}),
);
uj5u.com熱心網友回復:
使用startDate.millisecondsSinceEpoch.toString()
。uj5u.com熱心網友回復:
將你的日期轉換為ISO字串格式。在你的NodeJS決議碼中,當你從flutter發送它們時,你的編碼是什么。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/332248.html
標籤:
