0

I have 2 json

{ "B1": "some string" }

and

{ "B1": {"I1": 1, "I2": 2 } }

Is there a way - (through Attributes probably) to map Deserializing to such .NET objects. If string than data goes to B1_String, otherwise to B1.

public class A
{
    public string B1_String;
    public B B1;
}

public class B
{
    public int I1; public int I2;
}
Igor Golodnitsky
  • 4,456
  • 7
  • 44
  • 67

1 Answers1

0

   // b1 and b2 both are your json string

   JObject jb1 = JObject.Parse (b1);
   JObject jb2 = JObject.Parse (b2);

      IDictionary <string,JToken> dicb1 = jb1.SelecToken("B1");
      IDictionary <string,JToken> dicb2 = jb2.SelecToken("B1");

      JObject final;

       if(dicb1.Count > dicb2.Count)
        {
           final=dicb1;
        }
       else 
        {
           final=dicb2;
        }

   // now use the final

Dibu
  • 891
  • 5
  • 16