I am trying to get data from Baselinker.
But I am getting an error
Newtonsoft.Json.JsonReaderException: ‘Unexpected character encountered while parsing value: S. Path ”, line 0, position 0.’
The same in WPF
private async void Button_Clicked(object sender, EventArgs e)
{
using (var httpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(new HttpMethod("POST"), "https://api.baselinker.com/connector.php"))
{
request.Headers.TryAddWithoutValidation("X-BLToken", "AAA-BBB-CCC");
request.Content = new StringContent("method=getOrders¶meters=%7B%22date_from%22%3A+1407341754%7D");
request.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");
var response = await httpClient.SendAsync(request);
var oMycustomclassname = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(Convert.ToString(response));
labelek.Text = oMycustomclassname;
}
}
}
Help
2
Answers
Convert.ToString(response)
isn’t the right way to get the body of an HTTP response as a string. That’s likely to return"System.Net.Http.HttpResponseMessage"
which clearly isn’t JSON.I suspect you want:
An alternative: