Ich möchte durch den folgenden JSON durchlaufen und muss nur Namen aus dem JSON herausnehmen. Kann jemand helfen. Ich kann keine Klasse erstellen, da in einer anderen Klasse bereits dieselben Eigenschaften vorhanden sind.Iterieren durch JSON C#
{ "response": {
"status": {
"success": "true",
"code": 200,
"message": "SUCCESS"
},
"organization": {
"custom_fields": [
{
"field": [
{
"name": "age_group",
"label": "Age Group",
"type": "text",
"datatype": "String",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "birthday",
"label": "Birthday",
"type": "datepicker",
"datatype": "String",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "comebackfor",
"label": "comebackfor",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "customer_feedback",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "countries",
"label": "countries",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "gender",
"label": "Gender",
"type": "select",
"datatype": "String",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "{\"Male\":\"Male\",\"Female\":\"Female\"}",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "houseblockno",
"label": "houseblockno",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "interest",
"label": "interest",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "likeproducts",
"label": "likeproducts",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "customer_feedback",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "maritalstatus",
"label": "maritalstatus",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "nationality",
"label": "nationality",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "occupation",
"label": "occupation",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "pincode",
"label": "Pincode",
"type": "text",
"datatype": "String",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "rateus",
"label": "rateus",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "customer_feedback",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "salutation",
"label": "salutation",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "service",
"label": "service",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "customer_feedback",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "streetname",
"label": "streetname",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "suggestions",
"label": "suggestions",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "customer_feedback",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
},
{
"name": "unitno",
"label": "unitno",
"type": "text",
"datatype": "Boolean",
"default": "",
"phase": "1",
"position": "0",
"rule": "",
"regex": "",
"error": "",
"options": "",
"scope": "loyalty_registration",
"is_mandatory": "0",
"is_updatable": "1",
"is_disabled": "0",
"disabled_at_server": "0"
}
]
}
]
}
}
}
Es ist nicht wirklich klar, was du meinst. Warum kann man das nicht einfach in eine Klasse deserialisieren und die gewünschten Werte erhalten? Der Deserializer von Newtonsoft macht das ziemlich trivial. – David
Gehen Sie hier und fügen Sie Ihre JSON hier, um es zu Ihrem Kurs zu generieren oder Sie können dies direkt aus Visual Studio sowie http://json2csharp.com/ – MethodMan
json.net ist Ihr Freund – pm100