# การซีเรียลไลซ์ JSON (.NET) > System.Text.Json, JsonSerializer, custom converters, naming policies, การจัดการ null - 20 คำถามสัมภาษณ์ - Mid-Level - [คำถามสัมภาษณ์: .NET](https://sharpskill.dev/th/technologies/dotnet/interview-questions.md) ## 1. namespace หลักสำหรับการซีเรียลไลซ์ JSON ใน .NET สมัยใหม่คืออะไร? **คำตอบ** System.Text.Json คือ namespace อย่างเป็นทางการสำหรับการซีเรียลไลซ์ JSON ใน .NET Core 3.0+ ซึ่งค่อยๆ เข้ามาแทนที่ Newtonsoft.Json (Json.NET) เนื่องจากมีประสิทธิภาพสูงกว่า รวมอยู่ในเฟรมเวิร์ก และปรับให้เหมาะกับสถานการณ์สมัยใหม่ Newtonsoft.Json ยังคงใช้ได้ผ่าน NuGet สำหรับความเข้ากันได้ย้อนหลังหรือฟีเจอร์ขั้นสูงที่ไม่มีใน System.Text.Json ## 2. ใช้เมธอดใดในการซีเรียลไลซ์อ็อบเจกต์ C# เป็นสตริง JSON? **คำตอบ** JsonSerializer.Serialize แปลงอ็อบเจกต์ C# เป็นสตริง JSON เมธอดสแตติกนี้รับอ็อบเจกต์ที่จะซีเรียลไลซ์และ JsonSerializerOptions (ทางเลือก) เพื่อปรับแต่งพฤติกรรม Serialize คืนค่า string ขณะที่ SerializeToUtf8Bytes คืนค่า byte[] เพื่อเพิ่มประสิทธิภาพโดยหลีกเลี่ยงการจัดสรร string ## 3. ข้อตกลงการตั้งชื่อเริ่มต้นของ System.Text.Json สำหรับพร็อพเพอร์ตี JSON คืออะไร? **คำตอบ** โดยค่าเริ่มต้น System.Text.Json จะคงชื่อพร็อพเพอร์ตี C# ไว้ทุกประการ (PascalCase ที่แยกแยะตัวพิมพ์ใหญ่เล็ก) หากพร็อพเพอร์ตี C# ชื่อ UserName JSON จะมี UserName หากต้องการ camelCase (userName) ต้องตั้งค่า JsonSerializerOptions ด้วย PropertyNamingPolicy = JsonNamingPolicy.CamelCase ซึ่งต่างจาก Newtonsoft.Json ที่ใช้ camelCase โดยค่าเริ่มต้น ## มีอีก 17 คำถาม - จะดีซีเรียลไลซ์สตริง JSON เป็นอ็อบเจกต์ C# ที่มีชนิดได้อย่างไร? - ใช้แอตทริบิวต์ใดในการละเว้นพร็อพเพอร์ตีระหว่างการซีเรียลไลซ์ JSON? สมัครฟรี: https://sharpskill.dev/th/login ## หัวข้อสัมภาษณ์ .NET อื่นๆ - [พื้นฐาน C#](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-basics.md): 25 คำถาม, Junior - [LINQ & Delegates](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-linq-delegates.md): 20 คำถาม, Junior - [พื้นฐานสำคัญของภาษา C#](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-language-essentials.md): 15 คำถาม, Junior - [พื้นฐาน ASP.NET Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/aspnet-core-fundamentals.md): 18 คำถาม, Junior - [วงจรชีวิตของ request ใน ASP.NET Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/aspnet-core-request-lifecycle.md): 20 คำถาม, Junior - [Configuration & Settings](https://sharpskill.dev/th/technologies/dotnet/interview-questions/configuration-settings.md): 20 คำถาม, Junior - [วงจรชีวิตของแอปพลิเคชัน](https://sharpskill.dev/th/technologies/dotnet/interview-questions/application-lifecycle.md): 20 คำถาม, Junior - [Dependency Injection](https://sharpskill.dev/th/technologies/dotnet/interview-questions/dependency-injection.md): 24 คำถาม, Mid-Level - [Entity Framework Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/entity-framework-core.md): 25 คำถาม, Mid-Level - [Minimal APIs](https://sharpskill.dev/th/technologies/dotnet/interview-questions/minimal-apis.md): 18 คำถาม, Mid-Level - [การพัฒนา Web API](https://sharpskill.dev/th/technologies/dotnet/interview-questions/web-api-development.md): 22 คำถาม, Mid-Level - [Async ใน ASP.NET Core](https://sharpskill.dev/th/technologies/dotnet/interview-questions/async-aspnet-core.md): 20 คำถาม, Mid-Level - [Authentication & Authorization](https://sharpskill.dev/th/technologies/dotnet/interview-questions/authentication-authorization.md): 18 คำถาม, Mid-Level - [HttpClient & Networking](https://sharpskill.dev/th/technologies/dotnet/interview-questions/httpclient-networking.md): 20 คำถาม, Mid-Level - [Entity Framework Core ขั้นสูง](https://sharpskill.dev/th/technologies/dotnet/interview-questions/ef-core-advanced.md): 25 คำถาม, Mid-Level - [ฟีเจอร์ขั้นสูงของ C#](https://sharpskill.dev/th/technologies/dotnet/interview-questions/csharp-advanced-features.md): 20 คำถาม, Mid-Level - [Clean Architecture](https://sharpskill.dev/th/technologies/dotnet/interview-questions/clean-architecture.md): 20 คำถาม, Mid-Level - [Logging, Monitoring & Observability](https://sharpskill.dev/th/technologies/dotnet/interview-questions/logging-monitoring.md): 22 คำถาม, Mid-Level - [Unit Testing และ xUnit](https://sharpskill.dev/th/technologies/dotnet/interview-questions/unit-testing-xunit.md): 20 คำถาม, Mid-Level - [การทดสอบแบบบูรณาการ](https://sharpskill.dev/th/technologies/dotnet/interview-questions/integration-testing.md): 18 คำถาม, Mid-Level - [Docker & Containerization](https://sharpskill.dev/th/technologies/dotnet/interview-questions/docker-containerization.md): 16 คำถาม, Mid-Level - [การจัดการแพ็กเกจ NuGet](https://sharpskill.dev/th/technologies/dotnet/interview-questions/nuget-package-management.md): 16 คำถาม, Mid-Level - [Memory Management & GC](https://sharpskill.dev/th/technologies/dotnet/interview-questions/memory-management-gc.md): 22 คำถาม, Senior - [การเขียนโปรแกรมแบบรีแอกทีฟ](https://sharpskill.dev/th/technologies/dotnet/interview-questions/reactive-programming.md): 24 คำถาม, Senior - [Async/await และรูปแบบ](https://sharpskill.dev/th/technologies/dotnet/interview-questions/async-await-patterns.md): 26 คำถาม, Senior - [.NET Design Patterns](https://sharpskill.dev/th/technologies/dotnet/interview-questions/dotnet-design-patterns.md): 24 คำถาม, Senior - [การเพิ่มประสิทธิภาพการทำงาน](https://sharpskill.dev/th/technologies/dotnet/interview-questions/performance-optimization.md): 22 คำถาม, Senior - [ความปลอดภัยและ Best Practices](https://sharpskill.dev/th/technologies/dotnet/interview-questions/security-best-practices.md): 24 คำถาม, Senior - [SignalR และเรียลไทม์](https://sharpskill.dev/th/technologies/dotnet/interview-questions/signalr-realtime.md): 22 คำถาม, Senior - [สถาปัตยกรรม Microservices](https://sharpskill.dev/th/technologies/dotnet/interview-questions/microservices-architecture.md): 25 คำถาม, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/th/technologies/dotnet/interview-questions/json-serialization