Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/276.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# 如何使用jarray解析json?_C#_Asp.net - Fatal编程技术网

C# 如何使用jarray解析json?

C# 如何使用jarray解析json?,c#,asp.net,C#,Asp.net,如何使用jarray解析此json创建自定义类 [ { "religion": "Hindu", "otherreligionidtype": "1", "caste": "SC", "personwithdhhhy": "No", "purpogfgggan": "Studies", "typeongghance": "dontknow", "proposehhhgenure": "dontknow", "repajjgjeq

如何使用jarray解析此json创建自定义类

[
  {
    "religion": "Hindu",
    "otherreligionidtype": "1",
    "caste": "SC",
    "personwithdhhhy": "No",
    "purpogfgggan": "Studies",
    "typeongghance": "dontknow",
    "proposehhhgenure": "dontknow",
    "repajjgjequency": "Monthly",
    "sajgjgank": "yes",
    "savijgjcno": "975568592379236",
    "mjjggde": "7397576",
    "ifggde": "658545",
    "spouseinfo": [
      {
        "spousename": "Roshni",
        "spousekycidtype": "PAN Card",
        "spousekycidno": "56753",
        "spousedob": "26/05/1989"
      }
    ],
    "nominejeinfo": [
      {
        "nomijjjjgjme": "Krrish",
        "nomineekjgype": "Aadhar Card",
        "nomineekjgdno": "87494726"
      }
    ]
  }
]
public class-spooseinfo
{
公共字符串名称{get;set;}
公共字符串spoosekycidtype{get;set;}
公共字符串spoosekycidno{get;set;}
公共字符串喷动对象{get;set;}
}
公共类Nominejeinfo
{
公共字符串nomijjjme{get;set;}
公共字符串类型{get;set;}
公共字符串kjgdno{get;set;}
}
公共类根对象
{
公共字符串{get;set;}
公共字符串OtherReligionId类型{get;set;}
公共字符串类型{get;set;}
公共字符串personwithdhhhy{get;set;}
公共字符串purpogfggan{get;set;}
公共字符串typeonghance{get;set;}
公共字符串ProposeHhGenure{get;set;}
公共字符串repajgjequency{get;set;}
公共字符串sajgank{get;set;}
公共字符串savijgjcno{get;set;}
公共字符串MJGgde{get;set;}
公共字符串ifggde{get;set;}
公共列表信息{get;set;}
公共列表nominejeinfo{get;set;}
}
我通常添加newtonsoft软件包

public class Spouseinfo
{
    public string spousename { get; set; }
    public string spousekycidtype { get; set; }
    public string spousekycidno { get; set; }
    public string spousedob { get; set; }
}

public class Nominejeinfo
{
    public string nomijjjjgjme { get; set; }
    public string nomineekjgype { get; set; }
    public string nomineekjgdno { get; set; }
}

public class RootObject
{
    public string religion { get; set; }
    public string otherreligionidtype { get; set; }
    public string caste { get; set; }
    public string personwithdhhhy { get; set; }
    public string purpogfgggan { get; set; }
    public string typeongghance { get; set; }
    public string proposehhhgenure { get; set; }
    public string repajjgjequency { get; set; }
    public string sajgjgank { get; set; }
    public string savijgjcno { get; set; }
    public string mjjggde { get; set; }
    public string ifggde { get; set; }
    public List<Spouseinfo> spouseinfo { get; set; }
    public List<Nominejeinfo> nominejeinfo { get; set; }
}
var deserializedlist=JsonConvert.DeserializeObject(yourjsonString);
编辑 用于阅读配偶姓名

var deserializedlist = JsonConvert.DeserializeObject<RootObject>(yourjsonString);

for(inti=0;i由于某种原因,您坚持使用JArray,因此这段代码应该是一个诀窍

for(int i=0;i<deserializedlist.spouseinfo.Count();i++)
{
 string tempspousename=deserializedlist.spouseinfo[i].spousename;
}
var json=JArray.Parse;
foreach(json.Children()中的JObject obj)
{
foreach(obj.Properties()中的JProperty属性)
{
if(property.Value作为JArray!=null)
{
var jsonArray=JArray.Parse(property.Value.ToString());
Console.WriteLine(property.Name+“:”);
foreach(jsonArray.Children()中的JObject o)
foreach(o.Properties()中的JProperty p)
{
Console.WriteLine(p.Name+“”+p.Value.ToString());
}
}
其他的
{
字符串名称=property.name;
字符串值=property.value.ToString();
Console.WriteLine(名称+“”+值);
}
}
}

在发布问题之前,您需要显示最小的努力。代码生成器也不是这样。您可以显示您的代码吗?您尝试了什么?我已经创建了类文件,但我想从SpooseInfo读取值,在创建json后字段是配偶姓名。添加newtonsoft包并反序列化了吗?现在您可以看到editi这是我编写的代码jarray jobj=jarray.parse(detailentry1);foreach(jobj中的var detail1){txt_pllexture.Text=detail1[“ProposedLoaContenture”].ToString();rbtn_religation.SelectedValue=detail1[“religation”].ToString();}您能否在问题中添加自定义类和JArray代码作为编辑。
   var json = JArray.Parse(s);
        foreach (JObject obj in json.Children<JObject>())
        {
            foreach (JProperty property in obj.Properties())
            {

                if (property.Value as JArray!=null)
                {
                    var jsonArray = JArray.Parse(property.Value.ToString());
                     Console.WriteLine(property.Name + ":");
                    foreach(JObject o in jsonArray.Children<JObject>())
                        foreach(JProperty p in o.Properties())
                        {

                            Console.WriteLine(p.Name + " " + p.Value.ToString());
                        }
                }
                else
                {
                    string name = property.Name;
                    string value = property.Value.ToString();
                    Console.WriteLine(name + " " + value);
                }
            }
        }