Reputation: 3133
I have the following string. I am getting the following error. Could you please let me know what could be wrong?
Unexpected character encountered while parsing value: C. Path '', line 0, position 0.
JsonTextReader error: System.Exception {Newtonsoft.Json.JsonReaderException}
Here is the JSON string I am getting from client.
Content-Type: application/json
Content-Disposition: attachment; filename="postData.json"
{"name":"test44","age":"66","gender":"B","dob":"10\/10\/2003","file":null}
Here is my code for parsing using 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);
}
Upvotes: 1
Views: 14311
Reputation: 1500065
You've included the HTTP headers in your JSON string - you don't want those. Your json
value should just be this:
{"name":"test44","age":"66","gender":"B","dob":"10\/10\/2003","file":null}
I've tested your code, and when including the headers I get the same exception as you, but without them it's fine.
You should look at how you're receiving the data to start with - it would normally be odd to get just those two headers along with the body. You haven't told us how the client is providing the data, but if they're giving those headers where they should just be giving the body, then it's a client error.
Upvotes: 5
Reputation: 86
Looks to me like it's reading the 'C' from the Content type declaration & is complaining, don't include http headers.
Upvotes: 1