JSON字符串解析错误.System.Exception {Newtonsoft.Json.JsonReaderException}

nav*_*100 1 c# json json.net

我有以下字符串.我收到以下错误.能告诉我可能出错的地方吗?

Unexpected character encountered while parsing value: C. Path '', line 0, position 0.
JsonTextReader error: System.Exception {Newtonsoft.Json.JsonReaderException}
Run Code Online (Sandbox Code Playgroud)

这是我从客户端获取的JSON字符串.

Content-Type: application/json
Content-Disposition: attachment; filename="postData.json"

{"name":"test44","age":"66","gender":"B","dob":"10\/10\/2003","file":null}
Run Code Online (Sandbox Code Playgroud)

这是我使用JSON.NET解析的代码.

JsonTextReader reader = new JsonTextReader(new StringReader(json));
while (reader.Read())
{
     if (reader.Value != null)
        Console.WriteLine("Token: {0}, Value: {1}", reader.TokenType, reader.Value);
     else
        Console.WriteLine("Token: {0}", reader.TokenType);
}
Run Code Online (Sandbox Code Playgroud)

Jon*_*eet 5

您已在JSON字符串中包含HTTP标头 - 您不需要这些标头.你的json价值应该仅仅是这样的:

{"name":"test44","age":"66","gender":"B","dob":"10\/10\/2003","file":null}
Run Code Online (Sandbox Code Playgroud)

我已经测试了你的代码,当包含标题时,我会得到与你相同的异常,但没有它们就没问题了.

你应该看一下你如何接收数据 - 通常很奇怪的是,只需要将这两个标题与正文一起获取.您还没有告诉我们客户端如何提供数据,但是如果他们将这些标题放在他们应该给予正文的位置,那么这就是客户端错误.