C# Could not Cast or Convert System.String to Class object

前端 未结 4 1486
甜味超标
甜味超标 2021-01-01 09:47

I am trying to deserialize a JSON string received from a Web API

try
{
    string r = await App.client.GetUser();

    App.Authentication = JsonConvert.Deser         


        
4条回答
  •  轮回少年
    2021-01-01 10:30

    It appears that the json you receive has been serialized twice - first from ApiResult to string, then to string again:

    "\"{\\"status\\":\\"0\\",\\"message\\":...
    

    The first double-quote might be added by your debugger, but the second (the escaped \" one) really appears to be part of the data you're processing. The error message also makes sense this way, it deserializes a string and then attempts to cast it to an ApiResult.

    Try deserializing the data as a string and then deserializing its result to an ApiResult, to be sure this is the case - and if so, the server code will need to be changed.

提交回复
热议问题