windows phone:反序列化 json 键和值并将其存储到模态

windows phone: deserialise and store both json key and value to modal

你好 guyzzzz 我想在模态中存储键和值 class...下面是我的 json..

 {
  "Example": [
    {
      "Invoice": {
        "TFDGFF": " 200",
        "BF": " 200",
        "MD": "10",
        "EFM": " 12",
        "ATT": "4"
      },
      "TF": "200"
    },
    {
      "Invoice": {
        "DF": " 49",
        "DR": " 49",
        "KJ": "4",
        "LKIH": " 14",
        "KJGU": "4"
      },
      "DF": "49"
    }

请告诉我如何反序列化这个 json 以便我可以在模态 class 中存储键和值以及模态 class 的设计应该如何?

public class Invoice
{
    public string TF { get; set; }
    public string BF { get; set; }
    public string MD { get; set; }
    public string EFM { get; set; }
    public string ATT { get; set; }
    public string FPK { get; set; }
}

public class Example
{
    public Invoice Invoice { get; set; }
    public string TF { get; set; }
}

public class RootObject
{
    public List<Example> Example { get; set; }
}

利用json2csharp.com

现在使用 newtonsoft 包反序列化你的 json

var obj = JsonConvert.DeserializeObject<RootObject>(yourstring);

新的JSON

public class RootObject
        {
            public List<Example> Example { get; set; }
        }

        public class Example
        {
            public Dictionary<string, string> Invoice { get; set; }           
        }

你用

来称呼它
string temp=@" { ""Example"": [ { ""Invoice"": { ""TFDGFF"": ""200"", ""BF"": ""200"", ""MD"": ""10"", ""EFM"": ""12"", ""ATT"": ""4"" }, ""TF"": ""200"" }, { ""Invoice"": { ""DF"": "" 49"", ""DR"": "" 49"", ""KJ"": ""4"", ""LKIH"": "" 14"", ""KJGU"": ""4"" }, ""DF"": ""49"" }]}";
            var obj = JsonConvert.DeserializeObject<RootObject>(temp);

有关绑定的新问题

for (int i = 0; i < obj.Example.Count(); i++)
                {
                    foreach (KeyValuePair<string, string> pair in obj.Example[i].Invoice)
                    {
                        string temp3 = pair.Key;
                        string temp2 = pair.Value;
                    }
                }