using Newtonsoft.Json.Linq;
public static void Main()
PrintApiResult("single object", Deserialize(@"
PrintApiResult("array", Deserialize(@"
static void PrintApiResult(string name, ApiResult result)
Console.WriteLine("Results from " + name);
foreach (var item in result.PropertyA)
Console.WriteLine("{" + item.First + ", " + item.Second + "}");
Console.WriteLine(result.SomethingElse);
static ApiResult Deserialize(string json)
JObject j = JObject.Parse(json);
var propA = j["propertyA"];
switch (propA.Type.ToString())
PropertyA = new[]{propA.ToObject<ApiItem>()},
SomethingElse = j["somethingElse"].ToObject<string>(),
return j.ToObject<ApiResult>();
throw new Exception("Invalid json with propertyA of type " + propA.Type.ToString());
public ApiItem[] PropertyA
public string SomethingElse