Merhaba Arkadaşlar,
Json xml’e göre daha az yer tutan ve kullanımı kolay olan bir veri tutma formatıdır. Geliştiriciler için gerçekten kolaydır.Newtonsoft Json ile Json formatını bilmeden bile dosyaları localde depolayıp tekrar dan obje formatına çevirebilmekteyiz. Newtonsoft.Json paketini Nuget ile Projemizin Referanslarına ekliyoruz.Ardından;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApplication1 { static class Program { /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { // Uzunca Initializer Kullanımı Student student = new Student(); student.Id = 1; student.Name = "Sehmus"; student.Other = ""; student.School = "Microsoft"; student.Surname = "GOKCE"; string json = JsonConvert.SerializeObject(student); Student s = JsonConvert.DeserializeObject<Student>(json); } } public class Student { public string Name { get; set; } public string Surname { get; set; } public string School { get; set; } public int Id { get; set; } public string Other { get; set; } public Student() { var bilinmeyenTip = new { x = 1, y = 2 }; } } } |