-4
我想遍歷下面的json,只需要從json中取出名稱。任何人都可以幫忙我無法創建任何類,因爲在其他類中已經有相同的名稱屬性。通過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"
}
]
}
]
}
}
}
這不太清楚你的意思。爲什麼你不能簡單地將它反序列化爲一個類,並從中獲得你想要的值? Newtonsoft的反序列化器使得這個工作非常簡單。 – David
去這裏粘貼你的json在這裏讓它生成你的json到一個類,或者你可以直接從Visual Studio中做到這一點http://json2csharp.com/ – MethodMan
json.net是你的朋友 – pm100