반응형
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" ] }
반응형
'[====== Development ======] > C#' 카테고리의 다른 글
| WPF 컨트롤 위치값 구하기 (0) | 2023.03.28 |
|---|---|
| C# JSON Array 읽는 방법 (0) | 2023.03.28 |
| C# 구조체 리스트 정렬 (0) | 2023.03.20 |
| C# Enum 타입을 리스트로 만드는 방법 (1) | 2023.03.16 |
| C# Tesseract를 이용한 OCR 검출 샘플 코드 (0) | 2023.03.14 |
