问题
What should happen when the value of a property is set to undefined in a json string. i.e:
{"Name":undefined}
The following example is using the json.net library. An exception is thrown when de-serializing the object.
JsonConvert.DeserializeObject<SimpleObject>("{\"Name\":undefined}");
public class SimpleObject
{
public string Name { get; set; }
}
Newtonsoft.Json.JsonReaderException was unhandled
Message=Error reading string. Unexpected token: Undefined. Path 'Value', line 1, position 18.
Source=Newtonsoft.Json
LineNumber=1
LinePosition=18
Path=Value
回答1:
I think the error is fine.
Jsonlint.org throws an error too.
And reading the documentation on json.org the "value" element may have the following variants:
string number object array true false null
As you can see, undefined is NOT listed. Object does also not count as undefined.
来源:https://stackoverflow.com/questions/10455675/undefined-behaviour-in-json