Deserialize JSON to 2 different models

前端 未结 9 1182
眼角桃花
眼角桃花 2021-02-06 23:42

Does Newtonsoft.JSON library have a simple way I can automatically deserialize JSON into 2 different Models/classes?

For example I get the JSON:

[{
  \"g         


        
9条回答
  •  时光说笑
    2021-02-06 23:53

    In your models, The name properties need to be strings, instead of integers. After correcting it.

    You can use Tuple class

    string json = @"[{'guardian_id':'1453','guardian_name':'Foo Bar','patient_id':'938','patient_name':'Foo Bar'}]";
    
    var combination = new Tuple, List>(JsonConvert.DeserializeObject>(json), JsonConvert.DeserializeObject>(json));
    

提交回复
热议问题