Facing JsonReaderException

32 views
Skip to first unread message

Vaibhav Ranjan

unread,
Oct 25, 2022, 12:25:49 PM10/25/22
to RestSharp
Dear All,

I am new to restSharp and learning very basic of it. While creating a post request i am facing below error;

 CreateUsersTest
   Source: PostTest.cs line 15
   Duration: 2.4 sec

  Message: 
Test method RestSharpAPITest.PostTest.CreateUsersTest threw exception:
Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.

  Stack Trace: 
JsonTextReader.ParseValue()
JsonReader.ReadForType(JsonContract contract, Boolean hasConverter)
JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
Helper.GetContent[T](RestResponse response) line 44
UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
Demo.CreateUserTest(Object payload) line 32
PostTest.CreateUsersTest() line 22

I have attached a screnshot of my code written, please help me in resolving the issue. Thank you in advance.

RestSharpIssue.png
with Best Regards,
Vaibhav Ranjan

dharmesh sharma

unread,
Oct 27, 2022, 11:43:30 PM10/27/22
to rest...@googlegroups.com
Hii,
This is your json error your JSON is not format to serialisation or null.


--
You received this message because you are subscribed to the Google Groups "RestSharp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to restsharp+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/restsharp/83853909-dd62-4e18-ae3d-f7e0c4e42bb4n%40googlegroups.com.

Alexey Zimarev

unread,
Oct 29, 2022, 3:52:00 AM10/29/22
to RestSharp
The error clearly shows that it's XML returned in the response, not JSON. RestSharp chooses the deserializer based on the response content type, and it's apparently set to JSON, but the content is XML. It's the server issue, it returns the wrong content type. 
Reply all
Reply to author
Forward
0 new messages