I have an issue serializing a JSON string to a key/value dictionary. The code is like:
var parameters = "{\"id\":123}";
JsonConvert.DeserializeObject<Dictionary<string, string>>(parameters);
This example seems work perfectly, giving me {[id,123]}.
Now. When I change the number to something like '070809' I suddenly get an exception: "Newtonsoft.Json.JsonReaderException: Input string '070809' is not a valid number. Path 'id', line 1, position 12. ---> System.FormatException: Additional non-parsable characters are at the end of the string."
var parameters = "{\"id\":070809}";
JsonConvert.DeserializeObject<Dictionary<string, string>>(parameters);
Any suggestions?
Your second example isn't valid JSON. Recall that JSON is based on JavaScript, and in that language any numeric literal that starts with a 0 is interpreted as an octal number. Valid octal digits are 0-7, so if the literal contains an 8 or 9 then it cannot be parsed and will raise an error. ('010203' works because it is a valid octal literal but '070809' is not)