CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Collections;
using System.Runtime.Serialization;
using System.Dynamic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
public class Item
{
public Item() { this.CustomFields = new Dictionary<string, JToken>(); }
public string flowState { get; set; }
public long id { get; set; }
public Guid uid { get; set; }
[JsonExtensionData]
public IDictionary<string, JToken> CustomFields { get; private set; }
}
public class RootObject
{
public RootObject() { this.items = new List<Item>(); }
public Guid application_uid { get; set; }
public string formId { get; set; }
public int recordCount { get; set; }
public List<Item> items { get; set; }
}
public class TestClass
{
static string GetJson()
{
var json = @"{
""application_uid"":""3912d337-b797-4508-8c95-c76df8888ada"",
""formId"":""F_Form1"",
""recordCount"":1,
""items"":[
{
""lastModified"":""2015-12-11T20:07:25.774Z"",
""lastModifiedBy"":{
""displayName"":""Anonymous Guest User"",
""email"":"""",
""login"":""Anonymous Guest User""
},
""created"":""2015-12-11T20:07:25.774Z"",
""createdBy"":{
""displayName"":""Anonymous Guest User"",
""email"":"""",
""login"":""Anonymous Guest User""
},
""draft_ownerid"":"""",
""flowState"":""ST_End"",
""id"":20,
""uid"":""5928bb18-5b53-43f9-8831-baab042e1ca2"",
""F_ReceivedYorN"":""Y"",
""F_ContractNumber"":""5556420121"",
""F_FileNumber"":""0630250"",
""F_SubscriberLastName"":""JEFFERY""
},
{
""lastModified"":""2015-12-11T20:07:25.774Z"",
""lastModifiedBy"":{
""displayName"":""Anonymous Guest User"",
""email"":"""",
""login"":""Anonymous Guest User""
},
""created"":""2015-12-11T20:07:25.774Z"",
""createdBy"":{
""displayName"":""Anonymous Guest User"",
""email"":"""",
""login"":""Anonymous Guest User""
},
""draft_ownerid"":"""",
""flowState"":""ST_End"",
""id"":40,
""uid"":""1111bb18-1111-43f9-8831-baab042e1ca2"",
""F_SomeCustomProperty1"":""Y"",
""F_SomeCustomProperty2"":""5556420121"",
""F_SomeCustomProperty3"":""0630250"",
""F_SomeCustomProperty4"":""JEFFERY""
}
]
}";
return json;
}
public static void Test()
{
var json = GetJson();
Console.WriteLine("Raw Json:\n");
Console.WriteLine(JToken.Parse(json));
Console.WriteLine("");
var root = JsonConvert.DeserializeObject<RootObject>(json);
foreach (var item in root.items)
{
Console.WriteLine(string.Format("Showing custom properties for Item id {0}, uid {1}, flowState \"{2}\":", item.id, item.uid, item.flowState));
{
foreach (var field in item.CustomFields)
{
Console.WriteLine(string.Format(" - Field: \"{0}\":\n Value: {1}", field.Key, JsonConvert.SerializeObject(field.Value)));
}
Console.WriteLine("");
}
}
}
}
public class Program
{
public static void Main()
{
Console.WriteLine(string.Format("Json.NET version: {0}.\n", typeof(JsonSerializer).Assembly.FullName));
TestClass.Test();
}
}