using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
""LinkType1"": ""google"",
""LinkUrl1"": ""https://plus.google.com/test"",
""LinkType2"": ""facebook"",
""LinkUrl2"": ""https://www.facebook.com/test"",
""LinkType3"": ""linkedin"",
""LinkUrl3"": ""http://www.linkedin.com/test"",
""errorMessage"": ""Success""
LinksResult result = JsonConvert.DeserializeObject<LinksResult>(json);
foreach (LinkData link in result.Links)
Console.WriteLine(string.Format("{0}: {1} ({2})", link.LinkType, link.LinkUrl, (link.LinkShow ? "show" : "hide")));
class LinksResultConverter : JsonConverter
public override bool CanConvert(Type objectType)
return (objectType == typeof(LinksResult));
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
JObject obj = JObject.Load(reader);
LinksResult result = new LinksResult();
result.Count = (int)obj["count"];
result.ErrorCode = (int)obj["errorCode"];
result.ErrorMessage = (string)obj["errorMessage"];
result.Links = new List<LinkData>();
for (int i = 1; i <= result.Count; i++)
string index = i.ToString();
LinkData link = new LinkData();
link.LinkType = (string)obj["LinkType" + index];
link.LinkUrl = (string)obj["LinkUrl" + index];
link.LinkShow = (int)obj["LinkShow" + index] == 1;
public override bool CanWrite
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
throw new NotImplementedException();
[JsonConverter(typeof(LinksResultConverter))]
public List<LinkData> Links { get; set; }
public int Count { get; set; }
public int ErrorCode { get; set; }
public string ErrorMessage { get; set; }
public string LinkType { get; set; }
public string LinkUrl { get; set; }
public bool LinkShow { get; set; }