Marid Marid - 1 year ago 124
JSON Question

C# Dictionary to Json Format

This Question is related to Json data format. I have a dictionary with Key value pair.
ConfigA 1200
ConfigB 1500
ConfigC 800
ConfigD 2
.I need to convert the all dictionary values to 1 json format
Could anyone help me how to do it ?

Answer Source

Add System.Web.Extensions.dll and try the below code,

using System;
using System.Collections.Generic;
using System.Web.Script.Serialization;

public class Program
    public static void Main()
        var dictionary = new Dictionary<string, int> {
            {"ConfigA", 1200},
            {"ConfigB", 1500},
            {"ConfigC", 800},
            {"ConfigD", 2}

        var serializer = new JavaScriptSerializer();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download