2

I'm trying to pull down some data from a Web Service using Flurl but I'm getting the error:

Unexpected character encountered while parsing value: s. Path '', line 0, position 0. 

My code is:

var responseString = ("foobar")
            .WithHeader("Authorization", "Bearer f848e6d088a3324fc13d0a989296406b12f84730")
            .WithHeader("Accept", "application/json")
            .GetAsync()
            .ReceiveJson<HerdData>();

....

public class HerdData
{
    public List<Herd> data { get; set; }
}

I can't seem to get any data back and not sure what's going wrong as in Post Man I can access the data using the URL and auth token.

SmiffyKmc
  • 801
  • 1
  • 16
  • 34

1 Answers1

4

This error usually occurs when trying to deserialize non-json data.
You are using ReceiveJson(), you should check whether you are getting JSON data from the web service.
You could try to use ReceiveString() to get your data.

Billy Liu - MSFT
  • 2,168
  • 1
  • 8
  • 15
  • Correct. That error is bubbling up from Json.NET, which Flurl uses for serialization. – Todd Menier Mar 15 '18 at 16:53
  • Check the data you receive in Postman against the structure of HerdData. Use Newtonsoft to annotate members of HerdData to ensure the structure and corresponding property names align with your expected results. – Cody Hicks Mar 22 '18 at 13:14