Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/314.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# windows phone:反序列化json键和值并将其存储到modal_C#_Windows Phone 8_Windows 7_Windows Phone 8.1_Json Deserialization - Fatal编程技术网

C# windows phone:反序列化json键和值并将其存储到modal

C# windows phone:反序列化json键和值并将其存储到modal,c#,windows-phone-8,windows-7,windows-phone-8.1,json-deserialization,C#,Windows Phone 8,Windows 7,Windows Phone 8.1,Json Deserialization,你好,Guyzzz我想在模式类中存储键和值…下面是我的json { "Example": [ { "Invoice": { "TFDGFF": " 200", "BF": " 200", "MD": "10", "EFM": " 12", "ATT": "4" }, "TF": "200" }, { "Invoice": {

你好,Guyzzz我想在模式类中存储键和值…下面是我的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,以便我可以在模式类中存储键和值,模式类的设计应该如何??

公共类发票
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; }
}
{ 公共字符串TF{get;set;} 公共字符串BF{get;set;} 公共字符串MD{get;set;} 公共字符串EFM{get;set;} 公共字符串ATT{get;set;} 公共字符串FPK{get;set;} } 公开课范例 { 公共发票{get;set;} 公共字符串TF{get;set;} } 公共类根对象 { 公共列表示例{get;set;} }
利用

现在使用newtonsoft包来反序列化json

var obj = JsonConvert.DeserializeObject<RootObject>(yourstring);
var obj=JsonConvert.DeserializeObject(yourstring);
用于新的JSON

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

        public class Example
        {
            public Dictionary<string, string> Invoice { get; set; }           
        }
公共类根对象
{
公共列表示例{get;set;}
}
公开课范例
{
公共字典发票{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);
string temp=@“{”示例“:[{”发票“:{”TFDGFF“:“200”,“BF“:“200”,“MD”,“10”,“EFM”,“12”,“ATT”,“4”,“TF”,“TF”,“200”,“49”,“DR”,“49”,“KJ”,“4”,“LKIH”,“14”,“KJGU”,“4”,“DF”,“49”,“49”}”;
var obj=JsonConvert.DeserializeObject(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;
                    }
                }
for(int i=0;i
@jenin:我已经知道了……这不存储json的键……我的json中有动态键……所以我还需要将键存储在modalWell中。您提供的json没有任何动态数据。您可以使用Newtonsoft自动反序列化器而不是自定义类,或者最好的方法是创建一个命令式对象并充分利用其核心价值pair@jenin:由于我的json数据包含多个“发票”键..如何将其存储在字典中??你能给我举个例子吗?你需要给我提供JSON,你的意思是有多个“发票”键,其中一个是动态的,因为在你提供的JSON中,所有的都属于预定义的键,这可能是我可能从服务器端得到的JSON。所以这些键取决于父“发票”。那么在这个场景中我能做什么呢?{“示例”:[{“发票”:{“TFDGFF”:“200”,“BF”:“200”,“MD”:“10”,“EFM”:“12”,“ATT”:“4”},“TF”:“200”},{“发票”:{“DF”:“49”,“KJ”:“4”,“LKIH”:“14”,“KJGU”:“4”},“DF”:“49”}