using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JsonConvertDemo
{
class Program
{
static void Main(string[] args)
{
// {"Id":1,"Name":"홍길동","Title":"진달래꽃 사진"}
Photo p = new Photo { Id = 1, Name = "홍길동", Title = "진달래꽃 사진" };
string json = JsonConvert.SerializeObject(p);
Console.WriteLine(json);
Photo p2 = JsonConvert.DeserializeObject<Photo>(json);
// [{"Id":1,"Name":"홍길동","Title":"진달래꽃 사진"},{"Id":2,"Name":"백두산","Title":"개나리꽃 사진"},{"Id":3,"Name":"한라산","Title":"유채꽃 사진"}]
List<Photo> photos = new List<Photo> {
new Photo { Id = 1, Name = "홍길동", Title = "진달래꽃 사진" },
new Photo { Id = 2, Name = "백두산", Title = "개나리꽃 사진" },
new Photo { Id = 3, Name = "한라산", Title = "유채꽃 사진" }
};
string lstJson = JsonConvert.SerializeObject(photos);
Console.WriteLine(lstJson);
List<Photo> photos2 = JsonConvert.DeserializeObject<List<Photo>>(lstJson);
}
}
public class Photo
{
public int Id { get; set; }
public string Name { get; set; }
public string Title { get; set; }
}
}