使用NewtonSoft JSO序列化器和堆栈数据结构。当我反序列化结构时,顺序会被颠倒。比较数字和字符串。
这里我做错了什么或者是否有解决该问题的方法?
这里我做错了什么或者是否有解决该问题的方法?
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
class Example
{
public static void Main()
{
Stack<string> numbers = new Stack<string>();
numbers.Push("one");
numbers.Push("two");
numbers.Push("three");
numbers.Push("four");
numbers.Push("five");
string json = JsonConvert.SerializeObject(numbers.ToArray() );
// A stack can be enumerated without disturbing its contents.
foreach (string number in numbers)
{
Console.WriteLine(number);
}
Console.WriteLine("\nPopping '{0}'", numbers.Pop());
Console.WriteLine("Peek at next item to destack: {0}",
numbers.Peek());
Console.WriteLine("Popping '{0}'", numbers.Pop());
Stack<string> ss = null;
if (json != null)
{
ss = JsonConvert.DeserializeObject<Stack<string>>(json);
}
}
}