.NET 도움말 Newtonsoft Jsonpath (How it Works for Developers) 커티스 차우 업데이트됨:7월 28, 2025 다운로드 IronPDF NuGet 다운로드 DLL 다운로드 윈도우 설치 프로그램 무료 체험 시작하기 LLM용 사본 LLM용 사본 LLM용 마크다운 형식으로 페이지를 복사하세요 ChatGPT에서 열기 ChatGPT에 이 페이지에 대해 문의하세요 제미니에서 열기 제미니에게 이 페이지에 대해 문의하세요 Grok에서 열기 Grok에게 이 페이지에 대해 문의하세요 혼란 속에서 열기 Perplexity에게 이 페이지에 대해 문의하세요 공유하다 페이스북에 공유하기 트위터에 공유하기 LinkedIn에 공유하기 URL 복사 이메일로 기사 보내기 If you've ever worked with JSON data in .NET, you've probably come across the Newtonsoft.Json library, a popular high-performance JSON framework for .NET. This tutorial aims to help beginners and intermediate users effectively understand and use this powerful library, with a focus on its system references, documentation, and any relevant release updates. Getting Started To start using Newtonsoft.Json, you first need to install it into your .NET project. This can be done through NuGet, the .NET package manager. In the NuGet Package Manager Console, type: Install-Package Newtonsoft.Json After successful installation, add the library to your .NET project by adding the following using statement: using Newtonsoft.Json; using Newtonsoft.Json; $vbLabelText $csharpLabel Parsing JSON with Newtonsoft.JSON Parsing JSON is essentially the process of converting a string in JSON format into a usable data structure in your .NET application. With Newtonsoft.Json, the process is straightforward. Let's look at a sample JSON object for a person: { "Name": "Iron Developer", "Age": 30, "Email": "irondeveloper@ironsoftware.com" } We can parse this JSON string into a C# object using the JsonConvert.DeserializeObject<T>() method where T is the type of the object we want to create. In this case, we'll create a Person class and parse the JSON into that. public class Person { public string Name { get; set; } public int Age { get; set; } public string Email { get; set; } } string jsonString = "JSON string here"; Person person = JsonConvert.DeserializeObject<Person>(jsonString); public class Person { public string Name { get; set; } public int Age { get; set; } public string Email { get; set; } } string jsonString = "JSON string here"; Person person = JsonConvert.DeserializeObject<Person>(jsonString); $vbLabelText $csharpLabel Now, the person object will contain the values from the JSON string. Working with JSON Files You'll often need to read or write JSON data from or to a file. Let's see how we can do that with Newtonsoft.Json. We'll use the File class from the System.IO namespace in this case. To read a JSON file and parse it into an object: string path = "path to your json file"; string jsonString = File.ReadAllText(path); Person person = JsonConvert.DeserializeObject<Person>(jsonString); string path = "path to your json file"; string jsonString = File.ReadAllText(path); Person person = JsonConvert.DeserializeObject<Person>(jsonString); $vbLabelText $csharpLabel To write an object to a JSON file: Person person = new Person() { Name = "John Doe", Age = 30, Email = "johndoe@example.com" }; string path = "path to your json file"; string jsonString = JsonConvert.SerializeObject(person); File.WriteAllText(path, jsonString); Person person = new Person() { Name = "John Doe", Age = 30, Email = "johndoe@example.com" }; string path = "path to your json file"; string jsonString = JsonConvert.SerializeObject(person); File.WriteAllText(path, jsonString); $vbLabelText $csharpLabel Working with Arrays In some cases, your JSON will include arrays. For instance, a Person object might have an array of Friends: { "Name": "John Doe", "Friends": [ { "Name": "Jane Doe", "Age": 28 }, { "Name": "Billy", "Age": 25 } ] } You can use the foreach loop to iterate over the JSON array: JArray friends = (JArray)jsonObject["Friends"]; foreach (JObject friend in friends) { string friendName = (string)friend["Name"]; Console.WriteLine(friendName); } JArray friends = (JArray)jsonObject["Friends"]; foreach (JObject friend in friends) { string friendName = (string)friend["Name"]; Console.WriteLine(friendName); } $vbLabelText $csharpLabel Note: jsonObject should be replaced with an actual JObject initialized from the JSON. Modifying and Writing JSON Newtonsoft.Json makes it easy to modify and write JSON. Let's say you need to update the Age value of our Person object. jsonObject["Age"] = 31; // Update the age jsonObject["Age"] = 31; // Update the age $vbLabelText $csharpLabel And then write it back to a string: string updatedJson = jsonObject.ToString(); File.WriteAllText(path, updatedJson); // Write back to the file string updatedJson = jsonObject.ToString(); File.WriteAllText(path, updatedJson); // Write back to the file $vbLabelText $csharpLabel Note: jsonObject should be replaced with an actual JObject initialized from the JSON. LINQ to JSON Newtonsoft.Json also provides functionality for querying and manipulating JSON objects using LINQ (Language Integrated Query). This is very powerful as it allows you to use all the standard LINQ operators to query a JSON object just as you would with XML or a collection of objects. Here's a sample showing how you can fetch the names of all Friends younger than 30: var youngFriends = jsonObject["Friends"].Where(f => (int)f["Age"] < 30) .Select(f => (string)f["Name"]); foreach (string name in youngFriends) { Console.WriteLine(name); } var youngFriends = jsonObject["Friends"].Where(f => (int)f["Age"] < 30) .Select(f => (string)f["Name"]); foreach (string name in youngFriends) { Console.WriteLine(name); } $vbLabelText $csharpLabel Note: jsonObject should be replaced with an actual JObject initialized from the JSON. Introduction to IronPDF Learn about IronPDF is a popular library in the .NET ecosystem that allows developers to create, edit, and extract data from PDF files. It's incredibly versatile and works seamlessly with other libraries, including Newtonsoft.Json. IronPDF excels in HTML to PDF conversion, ensuring precise preservation of original layouts and styles. It's perfect for creating PDFs from web-based content such as reports, invoices, and documentation. With support for HTML files, URLs, and raw HTML strings, IronPDF easily produces high-quality PDF documents. using IronPdf; class Program { static void Main(string[] args) { var renderer = new ChromePdfRenderer(); // 1. Convert HTML String to PDF var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"; var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent); pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf"); // 2. Convert HTML File to PDF var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath); pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf"); // 3. Convert URL to PDF var url = "http://ironpdf.com"; // Specify the URL var pdfFromUrl = renderer.RenderUrlAsPdf(url); pdfFromUrl.SaveAs("URLToPDF.pdf"); } } using IronPdf; class Program { static void Main(string[] args) { var renderer = new ChromePdfRenderer(); // 1. Convert HTML String to PDF var htmlContent = "<h1>Hello, IronPDF!</h1><p>This is a PDF from an HTML string.</p>"; var pdfFromHtmlString = renderer.RenderHtmlAsPdf(htmlContent); pdfFromHtmlString.SaveAs("HTMLStringToPDF.pdf"); // 2. Convert HTML File to PDF var htmlFilePath = "path_to_your_html_file.html"; // Specify the path to your HTML file var pdfFromHtmlFile = renderer.RenderHtmlFileAsPdf(htmlFilePath); pdfFromHtmlFile.SaveAs("HTMLFileToPDF.pdf"); // 3. Convert URL to PDF var url = "http://ironpdf.com"; // Specify the URL var pdfFromUrl = renderer.RenderUrlAsPdf(url); pdfFromUrl.SaveAs("URLToPDF.pdf"); } } $vbLabelText $csharpLabel Let's assume we have a requirement where we have JSON data, and we want to create a PDF report from that data. We can use Newtonsoft.Json for parsing the JSON data and IronPDF for creating the PDF. Let's see how we can do this. Installation of IronPDF Like Newtonsoft.Json, IronPDF is also available through NuGet. You can install it using the following command: Install-Package IronPdf Then you can include it in your project by adding: using IronPdf; using IronPdf; $vbLabelText $csharpLabel Use Case 1: PDF Creation from JSON Data In this use case, we'll demonstrate how to use Newtonsoft.Json and IronPDF to generate a PDF report from JSON data. This could be particularly useful for applications that create dynamic reports based on data stored in a JSON format. Here's a sample JSON file that we'll be working with: { "Title": "Sales Report", "Month": "August", "Year": "2023", "TotalSales": "10000", "ItemsSold": "500" } This JSON data represents a simple sales report. The first step is to read the JSON file, named 'data.json' here, and parse it into a dictionary using Newtonsoft.Json: string jsonString = File.ReadAllText("data.json"); var reportData = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString); string jsonString = File.ReadAllText("data.json"); var reportData = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString); $vbLabelText $csharpLabel After executing this code, you'll have a dictionary called reportData containing key-value pairs representing the properties and their values in the JSON file. Next, we generate an HTML template using the data from reportData. The keys from the reportData dictionary are used to insert the appropriate values into the HTML: string htmlContent = $@" <html> <head><title>{reportData["Title"]}</title></head> <body> <h1>{reportData["Title"]}</h1> <p>Month: {reportData["Month"]}</p> <p>Year: {reportData["Year"]}</p> <p>Total Sales: {reportData["TotalSales"]}</p> <p>Items Sold: {reportData["ItemsSold"]}</p> </body> </html>"; string htmlContent = $@" <html> <head><title>{reportData["Title"]}</title></head> <body> <h1>{reportData["Title"]}</h1> <p>Month: {reportData["Month"]}</p> <p>Year: {reportData["Year"]}</p> <p>Total Sales: {reportData["TotalSales"]}</p> <p>Items Sold: {reportData["ItemsSold"]}</p> </body> </html>"; $vbLabelText $csharpLabel Lastly, we use IronPDF to convert the HTML code into a PDF document. We use ChromePdfRenderer to create a PDF renderer, use it to convert the HTML to a PDF, and then save the PDF: var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf(htmlContent); pdf.SaveAs("Report.pdf"); var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf(htmlContent); pdf.SaveAs("Report.pdf"); $vbLabelText $csharpLabel Use Case 2: JSON to PDF Form In this use case, we will read JSON data to fill in form fields in a PDF document. For this example, let's consider we have the following JSON data: { "FirstName": "John", "LastName": "Smith", "PhoneNumber": "+19159969739", "Email": "John@email.com", "City": "Chicago" } This JSON represents personal information for a person. First, we use Newtonsoft.Json to read the JSON data from the file and parse it into a dictionary: string jsonString = File.ReadAllText("data.json"); var person = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString); string jsonString = File.ReadAllText("data.json"); var person = JsonConvert.DeserializeObject<Dictionary<string, string>>(jsonString); $vbLabelText $csharpLabel This software creates a dictionary called the person with keys "FirstName," "LastName," "PhoneNumber," "Email," and "City" and their corresponding values. Next, we open the PDF document using IronPdf and get the form: var doc = PdfDocument.FromFile("myPdfForm.pdf"); var form = doc.Form; var doc = PdfDocument.FromFile("myPdfForm.pdf"); var form = doc.Form; $vbLabelText $csharpLabel We can now use the person dictionary to fill the form fields in the PDF document: form.Fields[0].Value = person["FirstName"]; form.Fields[1].Value = person["LastName"]; form.Fields[2].Value = person["PhoneNumber"]; form.Fields[3].Value = person["Email"]; form.Fields[4].Value = person["City"]; form.Fields[0].Value = person["FirstName"]; form.Fields[1].Value = person["LastName"]; form.Fields[2].Value = person["PhoneNumber"]; form.Fields[3].Value = person["Email"]; form.Fields[4].Value = person["City"]; $vbLabelText $csharpLabel Each form field is associated with a key from the person's dictionary. Finally, we save the filled PDF form: doc.SaveAs("myPdfForm_filled.pdf"); doc.SaveAs("myPdfForm_filled.pdf"); $vbLabelText $csharpLabel This method will create a new PDF document with the form fields filled in with the data from the JSON file. This demonstrates how you can effectively use Newtonsoft.Json to parse JSON data and IronPDF to manipulate PDF documents. Use Case 3: PDF Metadata to JSON First, use IronPDF to extract the metadata from the PDF: var pdf = IronPdf.PdfDocument.FromFile("document.pdf"); var metadata = pdf.MetaData; var pdf = IronPdf.PdfDocument.FromFile("document.pdf"); var metadata = pdf.MetaData; $vbLabelText $csharpLabel Then, serialize this data into a JSON string using Newtonsoft.Json: string jsonString = JsonConvert.SerializeObject(metadata, Formatting.Indented); File.WriteAllText("metadata.json", jsonString); string jsonString = JsonConvert.SerializeObject(metadata, Formatting.Indented); File.WriteAllText("metadata.json", jsonString); $vbLabelText $csharpLabel In this code, the metadata object contains properties like Author, Title, CreateDate, etc. These are serialized into a JSON string and written to a file named "metadata.json." Combining Newtonsoft.Json and IronPDF allows you to convert data between PDF files and JSON, fulfilling a wide range of use cases. Conclusion To conclude, Newtonsoft.Json and IronPDF together provide a powerful and flexible solution for handling JSON data and generating PDF files in .NET. By parsing JSON data into .NET objects or dictionaries with Newtonsoft.Json, we can manipulate that data and use it in various contexts, such as filling in PDF forms or generating dynamic PDF reports from templates. IronPDF makes the process of creating and managing PDFs straightforward and efficient. This article introduced the libraries, highlighting some of their core functionality. However, both libraries have much more to offer. We strongly recommend checking their extensive documentation for a deep dive into their features and capabilities. If you're interested in trying out IronPDF, they offer a free trial of IronPDF so you can explore its features and evaluate whether it meets your needs before purchasing. Once you decide to continue with IronPDF, licensing starts at IronPDF Licensing Options which includes continued access to all the features we discussed and support and updates. This ensures you have the tools and assistance to effectively generate, manage, and manipulate PDF files in your .NET projects. 자주 묻는 질문 .NET에서 JSON 작업을 위해 Newtonsoft.Json을 설치하려면 어떻게 해야 하나요? NuGet 패키지 관리자를 사용하여 .NET 프로젝트에 Newtonsoft.Json 라이브러리를 설치할 수 있습니다. 패키지 관리자 콘솔에서 Install-Package Newtonsoft.Json 명령을 실행합니다. 설치가 완료되면 using Newtonsoft.Json;로 프로젝트에 포함하세요. JsonConvert.DeserializeObject()는 어떤 용도로 사용되나요? JsonConvert.DeserializeObject() 메서드는 JSON 데이터를 .NET 객체로 파싱하는 데 사용됩니다. 이 메서드는 JSON 문자열을 유형 T의 개체로 변환하여 C# 애플리케이션에서 JSON 데이터로 작업할 수 있도록 합니다. LINQ를 사용하여 JSON 데이터를 조작하려면 어떻게 해야 하나요? LINQ to JSON은 Newtonsoft.Json에서 제공하는 기능으로, LINQ 구문을 사용하여 JSON 개체를 쿼리하고 조작할 수 있게 해줍니다. 이 기능은 .NET 애플리케이션 내에서 JSON 데이터를 효율적으로 필터링하거나 검색하는 데 유용합니다. JSON 데이터에서 PDF 보고서를 생성하려면 어떻게 해야 하나요? JSON 데이터에서 PDF 보고서를 생성하려면 먼저 Newtonsoft.Json을 사용하여 JSON을 .NET 개체로 변환합니다. 그런 다음 이 데이터를 사용하여 HTML 템플릿을 만듭니다. HTML 템플릿을 PDF 문서로 변환하려면 IronPDF의 ChromePdfRenderer를 사용합니다. JSON 데이터를 사용하여 PDF 양식을 채울 수 있나요? 예, Newtonsoft.Json을 사용하여 JSON을 사전으로 파싱한 다음 IronPDF를 사용하여 이 데이터로 PDF 양식 필드를 채운 다음 채워진 PDF 문서를 저장하면 PDF 양식을 JSON 데이터로 채울 수 있습니다. PDF 메타데이터를 JSON으로 변환하려면 어떻게 해야 하나요? IronPDF를 사용하여 PDF에서 메타데이터를 추출하고 Newtonsoft.Json을 사용하여 JSON 문자열로 변환합니다. 이 프로세스를 통해 PDF 메타데이터를 JSON 형식으로 쉽게 저장하고 조작할 수 있습니다. Newtonsoft.Json과 IronPDF를 함께 사용하면 어떤 이점이 있나요? .NET 애플리케이션에서 IronPDF와 함께 Newtonsoft.Json을 사용하면 JSON 데이터를 처리하고 PDF 파일을 생성 또는 조작할 수 있어 동적 보고서 생성, 양식 작성, 데이터 교환과 같은 작업을 원활하게 수행할 수 있습니다. .NET에서 JSON 파일을 읽고 쓰려면 어떻게 해야 하나요? JSON 파일을 읽으려면 File.ReadAllText를 사용하여 JSON 문자열을 로드한 다음 JsonConvert.DeserializeObject로 파싱합니다. JSON을 작성하려면 JsonConvert.SerializeObject를 사용하여 객체를 직렬화한 다음 File.WriteAllText로 저장합니다. 커티스 차우 지금 바로 엔지니어링 팀과 채팅하세요 기술 문서 작성자 커티스 차우는 칼턴 대학교에서 컴퓨터 과학 학사 학위를 취득했으며, Node.js, TypeScript, JavaScript, React를 전문으로 하는 프론트엔드 개발자입니다. 직관적이고 미적으로 뛰어난 사용자 인터페이스를 만드는 데 열정을 가진 그는 최신 프레임워크를 활용하고, 잘 구성되고 시각적으로 매력적인 매뉴얼을 제작하는 것을 즐깁니다. 커티스는 개발 분야 외에도 사물 인터넷(IoT)에 깊은 관심을 가지고 있으며, 하드웨어와 소프트웨어를 통합하는 혁신적인 방법을 연구합니다. 여가 시간에는 게임을 즐기거나 디스코드 봇을 만들면서 기술에 대한 애정과 창의성을 결합합니다. 관련 기사 업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기 업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기 업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기 Math Floor C# (How it Works for Developers)C# AND (How it Works For Developers)
업데이트됨 12월 11, 2025 Bridging CLI Simplicity & .NET : Using Curl DotNet with IronPDF Jacob Mellor has bridged this gap with CurlDotNet, a library created to bring the familiarity of cURL to the .NET ecosystem. 더 읽어보기
업데이트됨 12월 20, 2025 RandomNumberGenerator C# Using the RandomNumberGenerator C# class can help take your PDF generation and editing projects to the next level 더 읽어보기
업데이트됨 12월 20, 2025 C# String Equals (How it Works for Developers) When combined with a powerful PDF library like IronPDF, switch pattern matching allows you to build smarter, cleaner logic for document processing 더 읽어보기