Creates a JSON graph of all of the field's client-side data : Json « Network « C# / C Sharp






Creates a JSON graph of all of the field's client-side data

 

using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web.Script.Serialization;
using System.Web.UI;


public static class SerializationUtility
{

    /// <summary>
    /// Creates a JSON graph of all of the field's client-side data.
    /// </summary>
    public static string ToJson(this Dictionary<string, Dictionary<string, DataItem>> dict)
    {
        var main = new Dictionary<string, Dictionary<string, object>>();
        foreach (var item in dict)
        {
            var temp = new Dictionary<string, object>();
            foreach (var item2 in item.Value.Where(x => x.Value.ClientSide))
                temp.Add(item2.Key, item2.Value.Value);

            main.Add(item.Key, temp);
        }
        var json = new JavaScriptSerializer();
        return json.Serialize(main);
    }
}

   
  








Related examples in the same category

1.JSON (JavaScript Object Notation) Utility Methods.
2.DataContractJsonSerializer Demo
3.Serializes/Deserializes source into a JSON string.
4.Removes Json null objects from the serialized string and return a new string(Extention Method)
5.Json String To Byte Array