[[oktatas:programozás:csharp:dotnetcore|< .Net Core]]
====== .Net Core JSON ======
* **Szerző:** Sallai András
* Copyright (c) Sallai András, 2022
* Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]]
* Web: https://szit.hu
===== Telepítés =====
Windowson NuGet-tel (Tools -> NuGet Package Manager -> Package Manager Console):
Install-Package Newtonsoft.Json
Windowson és Linuxon dotnet paranccsal:
dotnet add package Newtonsoft.Json
===== Használat =====
class Employee {
public string name;
public string city;
public Employee(string name, string city) {
this.name = name;
this.city = city;
}
}
using Newtonsoft.Json;
Console.WriteLine("JSON");
List employees = new List();
employees.Add(new Employee("Park Imre", "Szolnok"));
employees.Add(new Employee("Lenti Béla", "Szeged"));
employees.Add(new Employee("Orosz Károly", "Hatvan"));
employees.Add(new Employee("Pinti József", "Szolnok"));
var json = JsonConvert.SerializeObject(employees);
Console.WriteLine(json);