Я столкнулся с определенным условием десериализации стандартного, но довольно большого JSON.
{
"fields": [
{
"webhook": true,
"associated_lookup": null,
"json_type": "jsonobject",
"crypt": null,
"field_label": "Account Owner",
"tooltip": null,
"created_source": "default",
"field_read_only": true,
"section_id": 1,
"read_only": false,
"businesscard_supported": true,
"currency": {},
"id": "3565223000000002421",
"custom_field": false,
"lookup": {},
"visible": true,
"length": 120,
"view_type": {
"view": true,
"edit": true,
"quick_create": false,
"create": true
},
"subform": null,
"api_name": "Owner",
"unique": {},
"data_type": "ownerlookup",
"formula": {},
"decimal_place": null,
"pick_list_values": [],
"multiselectlookup": {},
"auto_number": {}
},
{
"webhook": true,
"associated_lookup": null,
"json_type": "string",
"crypt": null,
"field_label": "Rating",
"tooltip": null,
"created_source": "default",
"field_read_only": false,
"section_id": 1,
"read_only": false,
"businesscard_supported": true,
"currency": {},
"id": "3565223000000002423",
"custom_field": false,
"lookup": {},
"visible": true,
"length": 120,
"view_type": {
"view": true,
"edit": true,
"quick_create": false,
"create": true
},
"subform": null,
"api_name": "Rating",
"unique": {},
"data_type": "picklist",
"formula": {},
"decimal_place": null,
"pick_list_values": [
{
"display_value": "-None-",
"actual_value": "-None-"
},
{
"display_value": "Acquired",
"actual_value": "Acquired"
},
{
"display_value": "Active",
"actual_value": "Active"
},
{
"display_value": "Market Failed",
"actual_value": "Market Failed"
},
{
"display_value": "Project Cancelled",
"actual_value": "Project Cancelled"
},
{
"display_value": "Shut Down",
"actual_value": "ShutDown"
}
],
"multiselectlookup": {},
"auto_number": {}
},{
"webhook": true,
"associated_lookup": null,
"json_type": "string",
"crypt": null,
"field_label": "Account Type",
"tooltip": null,
"created_source": "default",
"field_read_only": false,
"section_id": 1,
"read_only": false,
"businesscard_supported": true,
"currency": {},
"id": "3565223000000002441",
"custom_field": false,
"lookup": {},
"visible": true,
"length": 120,
"view_type": {
"view": true,
"edit": true,
"quick_create": false,
"create": true
},
"subform": null,
"api_name": "Account_Type",
"unique": {},
"data_type": "picklist",
"formula": {},
"decimal_place": null,
"pick_list_values": [
{
"display_value": "-None-",
"actual_value": "-None-"
},
{
"display_value": "Analyst",
"actual_value": "Analyst"
},
{
"display_value": "Competitor",
"actual_value": "Competitor"
},
{
"display_value": "Customer",
"actual_value": "Customer"
},
{
"display_value": "Distributor",
"actual_value": "Distributor"
},
{
"display_value": "Integrator",
"actual_value": "Integrator"
},
{
"display_value": "Investor",
"actual_value": "Investor"
},
{
"display_value": "Other",
"actual_value": "Other"
},
{
"display_value": "Partner",
"actual_value": "Partner"
},
{
"display_value": "Press",
"actual_value": "Press"
},
{
"display_value": "Prospect",
"actual_value": "Prospect"
},
{
"display_value": "Reseller",
"actual_value": "Reseller"
},
{
"display_value": "Supplier",
"actual_value": "Supplier"
},
{
"display_value": "Vendor",
"actual_value": "Vendor"
}
],
"multiselectlookup": {},
"auto_number": {}
}
]}
Я прикрепил выше часть JSON. Мой код C # для десериализации и обработки был предоставлен ниже. Я собираюсь создать связанный список внутреннего тега «pick_list_values» для элемента, в котором тип данных помечен как список раскладки («data_type»: «picklist»).
JObject ZohoCRMFieldsJO = JObject.Parse(ZohoCRMFieldsJson);
IList<ZohoCRMFields> newZohoCRMField = ZohoCRMFieldsJO["fields"].Select(p => new ZohoCRMFields
{
zohocrmmoduleid = zohocrmmoduleid.ToString(),
webhook = (bool)p["webhook"],
json_type = (string)p["json_type"],
field_label = (string)p["field_label"],
created_source = (string)p["created_source"],
field_read_only = (bool)p["field_read_only"],
section_id = (string)p["section_id"],
read_only = (bool)p["read_only"],
id = (string)p["id"],
custom_field = (string)p["custom_field"],
length = (int)p["length"],
visible = (bool)p["visible"],
api_name = (string)p["api_name"],
data_type = (string)p["data_type"]
}).ToList();
foreach (var ZohoCRMField in newZohoCRMField)
{
if (ZohoCRMField.data_type == "picklist" )
{
var ZohoCRMPickListsProvider = new ZohoCRMPickListsProvider();
IList<ZohoCRMPickLists> newZohoCRMPickList = ZohoCRMFieldsJO["fields"].Select(p => new ZohoCRMPickLists
{
zohocrmpicklistmoduleid = zohocrmmoduleid,
zohocrmfieldid = (string)p["id"],
display_value = (string)p[newZohoCRMField.IndexOf(ZohoCRMField)]["pick_list_values"]["display_value"],
actual_value = (string)p[newZohoCRMField.IndexOf(ZohoCRMField)]["pick_list_values"]["actual_value"]
}).ToList();
}
}
Как я могу завершить десериализацию. список получения должен быть получен в соответствии с разделом, тип данных которого является списком выбора. Любые подходящие альтернативы также будут работать, но выходные данные должны быть в LinkedList <>.