亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何反序列化C#中具有相同元素集合的Json元素

如何反序列化C#中具有相同元素集合的Json元素

C#
達令說 2022-12-24 12:41:48
我在 json 中有一個元素集合,里面有與嵌套元素集合相同的元素集合,所以如何在 c# 中反序列化我已經試過了。我創建了一個 C# 元素類,其屬性也是同一類集合的屬性//C# Codeclass pages{    public System.Collections.ObjectModel.Collection<elements> elements { get; set; }    public string name { get; set; }}class elements{    public string type { get; set; }    public string name { get; set; }    public string title { get; set; }    public System.Collections.ObjectModel.Collection<choices> choices { get; set; }    public System.Collections.ObjectModel.Collection<elements> element { get; set; }}//My Json{"pages": [ {  "name": "page1",  "elements": [  { "type": "panel", "name": "Q1", "elements": [  {   "type": "text",   "name": "Q2",   "title": "What is your age ?"  },  {   "type": "radiogroup",   "name": "QHidden",   "choices": [    {     "value": "1",     "text": "<18"    },    {     "value": "2",     "text": "18-30"    },    {     "value": "3",     "text": "30-50"    },    {     "value": "4",     "text": ">50"     }     ]     }    ]    }   ]  }  ]  }
查看完整描述

1 回答

?
楊魅力

TA貢獻1811條經驗 獲得超6個贊

我創建了一個單獨的具有相同屬性的元素類


   class elements

   {

     public string type { get; set; }

     public string name { get; set; }

     public string title { get; set; }


     public System.Collections.ObjectModel.Collection<choices> choices { get; set; }


     public System.Collections.ObjectModel.Collection<elements2> element { get; set; 

     }

   }


   class elements2

   {

     public string type { get; set; }

     public string name { get; set; }

     public string title { get; set; }


     public System.Collections.ObjectModel.Collection<choices> choices { get; set; }

   }

這對我有用


查看完整回答
反對 回復 2022-12-24
  • 1 回答
  • 0 關注
  • 113 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號