C# Firebase数据库时间戳未序列化,解析值时遇到错误{.Path';date';,
我想检索firestore集合的时间戳数据,但我在分析值时遇到错误-{“意外字符:{.Path'date' 样本数据集C# Firebase数据库时间戳未序列化,解析值时遇到错误{.Path';date';,,c#,asp.net-mvc,firebase,google-cloud-firestore,C#,Asp.net Mvc,Firebase,Google Cloud Firestore,我想检索firestore集合的时间戳数据,但我在分析值时遇到错误-{“意外字符:{.Path'date' 样本数据集 {"Tyres":"12","sr_no":"","TruckNumber":"TS 12345","image_url":"https://firebasestorage.googleapis.com/v0/b/truck-
{"Tyres":"12","sr_no":"","TruckNumber":"TS 12345","image_url":"https://firebasestorage.googleapis.com/v0/b/truck-41c31.appsp.jpg?alt=media&token=2dc86208-7f71-4e3c-876c-70a80d4822bf","date":{}}
代码
firestore日期字段数据-2020年6月29日UTC 22:23:44+5:30时
foreach (DocumentSnapshot documentSnapshot in truckQuerySnapshot.Documents)
{
if (documentSnapshot.Exists)
{
Dictionary<string, object> city = documentSnapshot.ToDictionary();
city["date"] = DateTime.Now.ToString();//modified here for resolve
string json = JsonConvert.SerializeObject(city);
Truck newtruck = JsonConvert.DeserializeObject<Truck>(json);
newtruck.Docid = documentSnapshot.Id;
newtruck.date = documentSnapshot.CreateTime.Value.ToDateTime();
lstTruck.Add(newtruck);
}
}
{
if(documentSnapshot.Exists)
{
Dictionary city=documentSnapshot.ToDictionary();
city[“date”]=DateTime.Now.ToString();//在此处修改以解决此问题
字符串json=JsonConvert.SerializeObject(城市);
Truck newtruck=JsonConvert.DeserializeObject(json);
newtruck.Docid=documentSnapshot.Id;
newtruck.date=documentSnapshot.CreateTime.Value.ToDateTime();
lstruck.Add(newtruck);
}
}
我现在在序列化对象(城市)之前分配了datetime,我的错误消失了。您的
日期
在“示例数据集中”是一个空对象。无法解析为datetime。也就是说,“2020年6月29日22:23:44 UTC+5:30“也不是标准的DateTime,除非您使用自定义解析器,否则不会进行解析。我在序列化之前进行了修改,工作正常,city[“date”]=DateTime.Now.ToString();谢谢@Oerkelens如果您已解决此问题,请将其添加为答案,以便其他人更容易找到它?
{
[FirestoreProperty]
[Required]
public string TruckNumber { get; set; }
[FirestoreProperty]
[Required]
public string Tyres { get; set; }
public DateTime date { get; set; }
[FirestoreProperty]
[Required]
public string image_url { get; set; }
[FirestoreProperty]
[Required]
public string sr_no { get; set; }
}
foreach (DocumentSnapshot documentSnapshot in truckQuerySnapshot.Documents)
{
if (documentSnapshot.Exists)
{
Dictionary<string, object> city = documentSnapshot.ToDictionary();
city["date"] = DateTime.Now.ToString();//modified here for resolve
string json = JsonConvert.SerializeObject(city);
Truck newtruck = JsonConvert.DeserializeObject<Truck>(json);
newtruck.Docid = documentSnapshot.Id;
newtruck.date = documentSnapshot.CreateTime.Value.ToDateTime();
lstTruck.Add(newtruck);
}
}