How to get Flurl to ignore JSON hijack prevention

455 Views Asked by At

I am trying to consume a JSON API using Flurl

If I use .GetStringAsync() the API returns as follows:

{} && {identifier:'ID', label:'As at 15-11-2018 6:25 PM',items:[...]}

However, when I try .GetJsonAsync<MyObj>() the properties are all null, I assume because of the {} &&.

Is there any way to force Flurl to ignore this and use the actual JSON data, or do I have to use .GetStringAsync(), manually remove the {} && and deserialize?

1

There are 1 best solutions below

1
Shevek On

It doesn't look like there is an inbuilt way to do this with Flurl so my workaround is to use Flurl's string method, manipulate the string, then use Newtonsoft to deserialize:

var response = await url.GetStringAsync();

if (!string.IsNullOrEmpty(response))
{
    response = response.Replace("{}&&", "");

    var feed = JsonConvert.DeserializeObject<MyObj>(response);

    ...do stuff...

}