我想創建一個代表下面的Json文檔(這是一個問卷形式)的C#基礎對象類。我可以輕鬆完成前三個三行,但我怎麼做"FormBody": { }
在病房的嵌套。如何將這個複雜的json文檔表示爲C#對象?
我已經看到傢伙在哪裏使用public IDictionary<string, object> FormBody {get; set;}
。我可以將它傳遞給Json.Net並讓它爲我填充對象類嗎?或者還有其他方法嗎?
{
"FormTitle": "Product 27",
"FormId": "CCC12345",
"Type": "forms",
"FormBody": {
"image": {
"width": 450,
"height": 200,
"title": "ACME Insurance",
"location": "Images/Forms/sample.jpg"
},
"heading1": {
"text": "Commercial Crime"
},
"body1": {
"text": "Important Notice, It is important that you as the proposer provide full and detailed answers to all the questions to enable the insurer to properly assess the risk involved and that the quote will be fair"
},
"heading2": {
"text": "How to use this form"
},
"body2": {
"text": "Please answer the questions listed below by either selecting an answer from the provided list/ contorl or enter the information into the designated field"
},
"categories": [
{
"name": "Gerenal Information",
"questions": [
{
"questionNumber": "1",
"dependencyLevel": {
"question": "0",
"answer": "0"
},
"questionText": "Are there any subsidiary companies that need to be included?",
"answerOptions": {
"control": {
"type": "groupCheckBox",
"selectionOptions": {
"availibleSelectionAmount": "2",
"options": [
"Yes",
"No"
]
}
}
},
"selectedAnswer": {
"selection": "Yes"
}
},
{
"questionNumber": "1.1",
"dependencyLevel": {
"question": "1",
"answer": "Yes"
},
"questionText": "How many subsidiaries need to be included?",
"questionInformation": {
"text": "Please enter a number"
},
"answerOptions": {
"control": {
"type": "dropDownList",
"selectionOptions": {
"availibleSelectionAmount": "5",
"options": [
"1",
"2",
"3",
"4",
"5"
]
}
}
},
"selectedAnswer": {
"selection": "1"
}
},
{
"questionNumber": "1.2",
"dependencyLevel": {
"question": "1",
"answer": "Yes"
},
"questionText": "Does the proposer have branches, subsidiaries, entities which are based outside RSA?",
"questionInformation": {
"text": "Please select one of the following"
},
"answerOptions": {
"control": {
"type": "groupCheckBox",
"selectionOptions": {
"availibleSelectionAmount": "2",
"options": [
"Yes",
"No"
]
}
}
},
"selectedAnswer": {
"selection": "No"
}
}
]
},
{
"name": "HR",
"questions": [
{
"questionNumber": "2",
"dependencyLevel": {
"question": "0",
"answer": "0"
},
"questionText": "How often does someone who is not normally involved in the payroll's update and preperation check on the payroll?",
"questionInformation": {
"text": "Please select one from the list"
},
"answerOptions": {
"control": {
"type": "dropDownList",
"selectionOptions": {
"availibleSelectionAmount": "5",
"options": [
"At least ounce a month",
"At least ounce a quater",
"At least every 6 months",
"Less than ounce a month",
"Less often"
]
}
}
},
"selectedAnswer": {
"selection": "At least ounce a month"
}
}
]
},
{
"name": "Accounting",
"information": "An owner/manger is an individual who owns most of the proposers shares and runs the business",
"questions": [
{
"questionNumber": "3",
"dependencyLevel": {
"question": "0",
"answer": "0"
},
"questionText": "Does the proposer's processes allow for someone to make payments without the owner/manager's knowledge",
"questionInformation": {
"text": "Please select one from the list"
},
"answerOptions": {
"control": {
"type": "dropDownList",
"selectionOptions": {
"availibleSelectionAmount": "5",
"options": [
"At least ounce a month",
"At least ounce a quater",
"At least every 6 months",
"Less than ounce a month",
"Less often"
]
}
}
},
"selectedAnswer": {
"selection": "At least ounce a month"
}
},
{
"questionNumber": "3.1",
"dependencyLevel": {
"question": "3",
"answer": "2"
},
"questionText": "Is dual authority required for EFTs?",
"questionInformation": {
"text": "Please select one"
},
"answerOptions": {
"control": {
"type": "checkBox",
"selectionOptions": {
"availibleSelectionAmount": "2",
"options": [
"Yes",
"No"
]
}
}
},
"selectedAnswer": {
"selection": "Yes"
}
},
{
"questionNumber": "3.2",
"dependencyLevel": {
"question": "3.1",
"answer": "Yes"
},
"questionText": "Are the people loading and releasing the payments both to check that the payments are made against a suitible authorisation document(e.g. signed purchase order, delivery note or similar)?",
"questionInformation": {
"text": "Please select one"
},
"answerOptions": {
"control": {
"type": "checkBox",
"selectionOptions": {
"availibleSelectionAmount": "2",
"options": [
"Yes",
"No"
]
}
}
},
"selectedAnswer": {
"selection": "Yes"
}
},
{
"questionNumber": "4",
"dependencyLevel": {
"question": "0",
"answer": "0"
},
"questionText": "Does the proposer have an annual formal budgeting process and is management approval required for payments which fall outside the budget?",
"questionInformation": {
"text": "Please select one from the list"
},
"answerOptions": {
"control": {
"type": "dropDownList",
"selectionOptions": {
"availibleSelectionAmount": "4",
"options": [
"No formal budget",
"Yes, there is a budget but it is a guideline only and is not strictly enforced",
"Yes, there is a formal budget and any deviations require managemant approval",
"Yes, there is a formal budget but small purchases outside the budget do not require management approval"
]
}
}
},
"selectedAnswer": {
"selection": "Yes, there is a formal budget and any deviations require managemant approval"
}
}
]
},
{
"name": "Cash",
"questons": [
{
"questionNumber": "5",
"dependencyLevel": {
"question": "0",
"answer": "0"
},
"questionText": "What is the typical maximum amount of cash and near cash on hand at any one time? This includes petty cash, payments by debtors, creditor's payments, etc. Near cash includes coins and negotiables such as cheques, etc.",
"questionInformation": {
"text": "Please select one from the list"
},
"answerOptions": {
"control": {
"type": "dropDownList",
"selectionOptions": {
"availibleSelectionAmount": "5",
"options": [
"Less than R 50,000",
"Less than R 100,000",
"Less than R 250,000",
"Less than R 2,500,000",
"More than R 2,500,000"
]
}
}
},
"selectedAnswer": {
"selection": "More than R 2,500,000"
}
},
{
"questionNumber": "5.1",
"dependencyLevel": {
"question": "5",
"answer": "More than R 2,500,000"
},
"questionText": "Is the proposer paid in cash for goods/services?",
"questionInformation": {
"text": "Please select one from the list"
},
"answerOptions": {
"control": {
"type": "dropDownList",
"selectionOptions": {
"availibleSelectionAmount": "5",
"options": [
"Never",
"Less than once a month",
"Somethimes",
"Often",
"Very Often"
]
}
}
},
"selectedAnswer": {
"selection": "Very Often"
}
},
{
"questionNumber": "5.1.1",
"dependencyLevel": {
"question": "5.1",
"answer": "4"
},
"questionText": "How often are cash reconciliations done?",
"questionInformation": {
"text": "Please select one from the list"
},
"answerOptions": {
"control": {
"type": "dropDownList",
"selectionOptions": {
"availibleSelectionAmount": "5",
"options": [
"Never",
"Less than once a month",
"Somethimes",
"Often",
"Very Often"
]
}
}
},
"selectedAnswer": {
"selection": "Often"
}
}
]
}
]
}
}
啊,使用的命名空間是'System.Runtime.Serialization' – wojtuch
那麼你將如何做我的答案中列出的類? –
我向你展示了開始 - 字符串FormTitle,FormId,Type作爲「main」類的字段,然後是由'heading1','body1'組成的複雜類型'FormBody'(單獨的類) 'heading2','body2',它們每個都包含'String text'作爲唯一的字段 - 這意味着您可以創建一個類並將它用作所有四個類型的類型... 我希望我讓自己清楚.. look密切關注你的json,你會看到如何建模。 但不要指望其他人爲你編寫代碼:) – wojtuch