Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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
Json中未定义的行为_Json_Json.net - Fatal编程技术网

Json中未定义的行为

Json中未定义的行为,json,json.net,Json,Json.net,当json字符串中的属性值设置为未定义时,应该发生什么。 i、 e: 下面的示例使用json.net库。反序列化对象时引发异常 JsonConvert.DeserializeObject<SimpleObject>("{\"Name\":undefined}"); public class SimpleObject { public string Name { get; set; } } Newtonsoft.Json.JsonReaderException was unha

当json字符串中的属性值设置为未定义时,应该发生什么。 i、 e:

下面的示例使用json.net库。反序列化对象时引发异常

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
JsonConvert.DeserializeObject(“{Name\”:undefined}”);
公共类SimpleObject
{
公共字符串名称{get;set;}
}
Newtonsoft.Json.JsonReaderException未处理
Message=读取字符串时出错。意外标记:未定义。路径“值”,第1行,位置18。
Source=Newtonsoft.Json
行号=1
LinePosition=18
路径=值

我认为这个错误没有问题

org也会抛出一个错误

阅读json.org上的文档,“value”元素可能有以下变体:

串 数 对象 排列 真的 假的 空的

如您所见,未定义的未列出。对象也不算作未定义

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