I get this error Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: <. Path '', line 0, position 0.'

Can anyone please help me to solve this problem Please and thank you.

string webAddress ="https://www.sandbox.paypal.com/cgi-bin/webscr";
System.Net.WebClient w = new System.Net.WebClient();
w.Headers[HttpRequestHeader.ContentType] ="application/x-www-form- urlencoded";
w.Encoding = System.Text.Encoding.UTF8;
string responseJson = w.UploadString(webAddress, data);
 string data ="[{MerchantId:'Kima.a, MerchantPassword:nice.coffee,CardNo {0},CardType {1},CardSecurity {2},'CardHolder {3}','CardExpiry {4}','Amount{5}'}]";

 data =(data, checkout.CardNumber, checkout.CardType, checkout.CSC, checkout.CardOwner, expiryDatePlaceHolder, grandTotal).ToString();

ReservationViewModel reservation = JsonConvert.DeserializeObject<ReservationViewModel>(responseJson);

closed as off-topic by poke, JSteward, Nat Pongjardenlarp, JumpingJezza, Alexei Levenkov Apr 16 at 1:27

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – poke, JSteward, JumpingJezza, Alexei Levenkov
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Would it be possible for you to post the value of responseJson? – devNull Apr 15 at 23:25
  • Yeah this is almost definitely a case of HTML and not JSON being returned. – ScottyD0nt Apr 15 at 23:34
  • devNull this is for the responseJson. string responseJson = w.UploadString(webAddress, data); and sorry for that I am using System.Net.WebClient w = new System.Net.WebClient(); – Ron Apr 15 at 23:38
  • I am new to this so can you please tell me a way to solve this problem ScottyD0nt – Ron Apr 15 at 23:39
  • @Ron That's just the declaration of that variable. The error you're seeing is occurring in JsonConvert.DeserializeObject<ReservationViewModel>(responseJson);. So in order to know why you're getting that exception, we need the actual content of responseJson when it is passed into JsonConvert.DeserializeObject – devNull Apr 16 at 0:07

Browse other questions tagged or ask your own question.