3

I am trying to convert a json string to a JObject using JObject.Parse, but running into the error "Error parsing positive infinity value. Path 'Modified.Date', line 1, position 52."

Here is the part of json that is throwing the error on -

{ ..., "Modified" : { "Date" : ISODate("2013-02-21T22:23:57.118Z"), "User" : "Admin" }, ...}

Here is the code I am using to do the parse -

var jobj = JObject.Parse(formJson)

Update: The json was generated by using mongodb's .ToJson() extension method, by sending in the following jsonwritersettings it generated json that was parsable by json.net - new JsonWriterSettings { OutputMode = JsonOutputMode.JavaScript };

2
  • 1
    That looks like a custom Date format. It's a combination of the IsoDateTime which defines the string and the default format (which normally looks like Date(Time in Milliseconds)). Any chance you can change the code that generates this JSON? Commented Feb 21, 2013 at 23:43
  • Yeah I was able to change the json generation code, the resulting json was {..., \"Modified\" : { \"Date\" : new Date(1361492718941), \"User\" : \"Admin\", ... } which was parsable by json.net Commented Feb 22, 2013 at 0:26

2 Answers 2

5

I think you need to lose the ISODate.

This works:

String MyJson = "{MyDate   : \"2013-02-21T22:23:57.118Z\" }";
var x = Newtonsoft.Json.Linq.JObject.Parse(MyJson);
Sign up to request clarification or add additional context in comments.

Comments

0

I tried using Regex and convert in C#:

Regex _regex = new Regex(@"\d\d\d\d-\d\d-\d\d");
                    Match _date = _regex.Match(<Your_Date_String>);
                    if (_date.Success)
                    {
                        var datetime = Convert.ToDateTime(_date.Value);
                    }

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.