using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
public static void Main()
string Json = @"[""error"",{""code"":2,""msg"":""This API Key is invalid""}]";
var result = JsonConvert.DeserializeObject<Result>(Json);
Console.WriteLine("String: " + result.String);
Console.WriteLine("Code: " + result.cm.Code);
Console.WriteLine("Msg: " + result.cm.Msg);
public long Code { get; set; }
public string Msg { get; set; }
[JsonConverter(typeof(ResultConverter))]
public string String { get; set; }
public CodeMsg cm { get; set; }
public class ResultConverter : JsonConverter
public override bool CanConvert(Type objectType)
return objectType == typeof(Result);
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
JArray array = JArray.Load(reader);
Result result = new Result
String = array[0].Value<string>(),
cm = array[1].ToObject<CodeMsg>(serializer)
public override bool CanWrite
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
throw new NotImplementedException();