JsonConvert.Deserializer indexing issues

后端 未结 4 615
情话喂你
情话喂你 2020-11-29 14:07

While playing around Stack collection in C# I encountered the following issue. Exactly I am not sure why it is happening. Please put some light on the reason and alternative

4条回答
  •  一生所求
    2020-11-29 14:15

    In Visual Studio 2019, this C# works:

    List ls = null;
    Stack ss = null;
    if (json != null)
    {
        ls = JsonConvert.DeserializeObject>(json);
        ss = new Stack(ls);
    }
    

    (This is an edit of the answer from here, which originally had an errant Reverse method call on the list that caused the opposite of the desired result.)

提交回复
热议问题