반응형
using Newtonsoft.Json;
using System;
using System.Collections.Generic;

public class Program
{
    public static void Main()
    {
        // create an array of items
        List<string> items = new List<string> { "item1", "item2", "item3" };

        // create a dictionary to hold the object properties
        Dictionary<string, object> jsonDict = new Dictionary<string, object>();
        jsonDict.Add("name", "myArray");
        jsonDict.Add("items", items);

        // serialize the dictionary to JSON
        string json = JsonConvert.SerializeObject(jsonDict);

        // print the JSON
        Console.WriteLine(json);
    }
}

 

{
    "name": "myArray",
    "items": [
        "item1",
        "item2",
        "item3"
    ]
}
반응형

+ Recent posts