Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# C“MongoDB驱动程序2.0转换”;“严格模式”;Json to";“mongo外壳模式”;B有声文件_C#_Mongodb_Serialization - Fatal编程技术网

C# C“MongoDB驱动程序2.0转换”;“严格模式”;Json to";“mongo外壳模式”;B有声文件

C# C“MongoDB驱动程序2.0转换”;“严格模式”;Json to";“mongo外壳模式”;B有声文件,c#,mongodb,serialization,C#,Mongodb,Serialization,我有一个“严格模式”Json字符串,其中日期前缀为“$date” "DateCreated\":{\"$date\":1444835457460} 我现在需要“mongo shell模式”中的字符串,其中 为了达到我使用的“严格模式” .ToJson((new JsonWriterSettings { OutputMode = JsonOutputMode.Strict }) 要转换回“mongo shell模式”,我尝试 运气不好,字符串没有转换,“$date”仍然存在(我希望是ISODa

我有一个“严格模式”Json字符串,其中日期前缀为“$date”

"DateCreated\":{\"$date\":1444835457460}
我现在需要“mongo shell模式”中的字符串,其中

为了达到我使用的“严格模式”

.ToJson((new JsonWriterSettings { OutputMode = JsonOutputMode.Strict })
要转换回“mongo shell模式”,我尝试

运气不好,字符串没有转换,“$date”仍然存在(我希望是ISODate…)


有什么想法吗?

我不确定这是否回答了你的问题,但是对于那些像我一样通过谷歌偶然发现这个问题的人来说,你可能会发现以下内容很有用

使用C#MongoDB.Driver包中的
BsonDocument.Parse

//var str: '{ "SomeDate": { "$date": "2010-10-10T10:10:00+00:00" } }'
BsonDocument.Parse(str); // Result: {{ "SomeDate": ISODate("2010-10-10T10:10:00Z) }}
这也适用于unix时间戳,例如:
{“$date”:1286705400000}

.ToJson((new JsonWriterSettings { OutputMode = JsonOutputMode.Shell})
//var str: '{ "SomeDate": { "$date": "2010-10-10T10:10:00+00:00" } }'
BsonDocument.Parse(str); // Result: {{ "SomeDate": ISODate("2010-10-10T10:10:00Z) }}