TableContinuationToken 没有从 JSON 正确反序列化

TableContinuationToken not getting Deserialised from JSON correctly

我在尝试从 Azure TableStorage 检索大型数据集时遇到问题。在多次尝试一次性获得它之后,我放弃了,现在正在使用 TableContinuation Token,它现在没有被反序列化 correctly.The 对象正在创建,但是所有 Next... 值(即 NextRowKey, NextPartitionKey 等为 NULL,当创建的 stringresponse 中您可以看到它应该填充的值...

我传递的 class 包含对象列表和令牌

public class FlorDataset 
{
    public List<FlorData> Flors { get; set; }
    public TableContinuationToken Token { get; set; }
}

控制器代码也不完全是火箭科学....

        [HttpGet, Route("api/list/{token}")]
    public IHttpActionResult FindAll(string token)
    {
        try
        {
            TableContinuationToken actualToken = token == "None"
                ? null
                : new TableContinuationToken()
                {
                    NextPartitionKey = NextPartition,
                    NextRowKey = token,
                    NextTableName = NextTableName
                };

            var x = Run(actualToken);
            Flors = x.Flors;
            actualToken = x.Token;
            NextTableName = actualToken.NextTableName;
            NextPartition = actualToken.NextPartitionKey;

                return Flors != null
                    ? (IHttpActionResult)new IsoncOkResult<FlorDataset>(x, this)
                    : NotFound();

        }
        catch (Exception ex)
        {
            Trace.TraceError(ex.ToString());
            return NotFound();
        }
    }

    private  FlorDataset Run(TableContinuationToken token)
    {
        return _repo.GetAllByYear("2016", token) as FlorDataset;
    }

调用我相当标准的 Web API 2 Controller 的调用代码是:

                do
            {
                try
                {
                    HttpResponseMessage response = null;
                    if (string.IsNullOrEmpty(token.NextRowKey))
                    {
                        response = await client.GetAsync("api/list/None");
                    }
                    else
                    {
                        response = await client.GetAsync($"api/list/{token.NextRowKey}");
                    }
                    if (response.IsSuccessStatusCode)
                    {
                        var stringresponse = await response.Content.ReadAsStringAsync();
                        var ds = JsonConvert.DeserializeObject<FlorDataset>(stringresponse);
                        token = ds.Token;
                        Flors.AddRange(ds.Flors);
                    }
                    else
                    {
                        token = null;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                    token = null;
                }
            } while (token != null);

好吧,这不是最好的解决方案,但这是目前唯一有效的方法,以防其他人在尝试相同的方法时遇到我的问题....

在调用代码位中,您在执行反序列化之前做了一些可怕的字符串替换....我实际上觉得发布这个很脏,所以如果有人想出更好的答案,请随时分享.....

if (response.IsSuccessStatusCode)
{
    var stringresponse = await response.Content.ReadAsStringAsync();
    stringresponse = stringresponse.Replace(">k__BackingField", "");
    stringresponse = stringresponse.Replace("<", "");
    var ds = JsonConvert.DeserializeObject<FlorDataset>(stringresponse);
    token = ds.Token;
    Flors.AddRange(ds.Flors);                      
}

不好,不漂亮,但确实有效!!!! :-D 现在要用漂白剂清洗我的手指!!!