Handling MongoDB's ISODate() when attempting to parse a serialized JSON string

前端 未结 6 1792
庸人自扰
庸人自扰 2021-02-07 11:00

I\'m using MongoDB via the official C# driver with an ASP.NET MVC web site.

I have the following C# model:

public class Contact
{
    public ObjectId Id          


        
6条回答
  •  长情又很酷
    2021-02-07 11:31

    If the JSON data is safe for eval (since its coming from your server it probably is) then you can do like so. It's not particularly pretty, but it gets the job done.

    http://jsfiddle.net/CVLhx/

    var str = '{"_id"  : ObjectId("52eaad4839b60812fca4bf28"),"Name": "Joe Blow","DateAdded" : ISODate("2014-01-30T19:51:35.977Z")}';
    
    function ObjectId(id) { return id;}
    function ISODate(d) {return d;}
    
    var obj = eval('(' + str + ')');
    console.log(obj);
    

提交回复
热议问题