But inside the deserialize function the value passed is not a valid JSON string.
I’t’s definitely a valid string when it’s passed into:
var response = await httpClient.GetAsync(requestUri);
var content = await response.Content.ReadAsStringAsync();
var page = content.FromJson<BlockPage>(); //in debugger is valid json string
but inside the Deserialize function it looks like it has some sort of escaping and is not a valid json string.
public static BlockPage Deserialize(string value)
{
//doesn't work because not a valid json string
var serial = value.FromJson<BlockPage>();
return serial;
}
Seems the issue is the original json string has a field that contains a html escaped property with a large json object in it. The json validates in json lint so it is escaped properly in response from API.
When it gets passed into the deserialize function the value parameter seems to have had another escaping process applied to it and it’s no longer a valid json string. The BlockPage class is irrelevant as the string passed to is not a valid json string so will fail regardless.
For your use case you will want to be using the JsConfig<T>.RawDeserializeFn override instead. Difference between DeSerializeFn and RawDeserializeFn is that DeSerializeFn assumes that the string will need to be unescaped whilst RawDeserializeFn doesn’t which is what is causing the issue.