Felhasználói eszközök

Eszközök a webhelyen


oktatas:programozas:csharp:dotnetcore:json

< .Net Core

.Net Core JSON

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

Employee.cs
class Employee {
    public string name;
    public string city;
    public Employee(string name, string city) {
        this.name = name;
        this.city = city;
    }
}
Program.cs
using Newtonsoft.Json;
 
Console.WriteLine("JSON");
 
List<Employee> employees = new List<Employee>();
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);
oktatas/programozas/csharp/dotnetcore/json.txt · Utolsó módosítás: 2024/02/18 22:12 szerkesztette: admin