[英]Deserialize numbered items into collection of objects
I am not sure how to correctly ask my question.我不知道如何正确地问我的问题。
I'm facing a problem using JSON.net: The point is, I am receiving this JSON from a webservice.我在使用 JSON.net 时遇到问题:关键是,我从 Web 服务接收到这个 JSON。 Apparently this thing has never heard of object oriented programming, and my JSON has the following exemplary structure:
显然这东西从来没有听说过object 面向编程,而我的JSON 具有以下示例结构:
"meta": {
“元”:{
"collection_t1_driver_selected_invoiceaccount": "911156","collection_t1_driver_selected_invoiceaccount": "911156",
"collection_t1_scandate": "11 mei 2020","collection_t1_scandate": "11 mei 2020",
"collection_t1_scandate-value": "2020-05-11","collection_t1_scandate-value": "2020-05-11",
"collection_t2_driver_selected_invoiceaccount": "911156","collection_t2_driver_selected_invoiceaccount": "911156",
"collection_t2_scandate": "11 mei 2020","collection_t2_scandate": "11 mei 2020",
"collection_t2_scandate-value": "2020-05-11",“collection_t2_scandate-value”:“2020-05-11”,
"collection_t3_driver_selected_invoiceaccount": "911156","collection_t3_driver_selected_invoiceaccount": "911156",
"collection_t3_scandate": "11 mei 2020","collection_t3_scandate": "11 mei 2020",
"collection_t3_scandate-value": "2020-05-11"“collection_t3_scandate-value”:“2020-05-11”
}}
As you can see there are 3 similar blocks.如您所见,有 3 个类似的块。 Is there any way to serialize this into a collection of 3 times the same object with 3 fields with JSON.net?
有什么方法可以将其序列化为具有 3 个字段和 JSON.net 的 3 倍相同 object 的集合?
Wow, 3 days and I post the same answer on each day: C# Convert Json to object with duplicated property name with different data type哇,3 天,我每天都发布相同的答案: C# Convert Json to object with duplicate property name with different data type
Basically you write a specific JsonConvert class that creates a 'union' of all the possible types and then parses the input field and adds the data to one of the union members.基本上,您编写一个特定的 JsonConvert class 创建所有可能类型的“联合”,然后解析输入字段并将数据添加到联合成员之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.