Advertisement
Naohiro19

Json.NET Test

Mar 4th, 2019
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Threading.Tasks;
  7. using Newtonsoft.Json;
  8. using Newtonsoft.Json.Serialization;
  9.  
  10. namespace JsonTestApp
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             var data = new UserModel();
  17.             data.UserID = 100;
  18.             data.UserName = "太郎";
  19.             data.LangCode = "ja";
  20.  
  21.             using (var jsonWrite = new StreamWriter("test.json"))
  22.             {
  23.                 var serialize = JsonConvert.SerializeObject(data);
  24.                 jsonWrite.WriteLine(serialize);
  25.             }
  26.  
  27.         }
  28.  
  29.         [JsonObject("user")]
  30.         public class UserModel
  31.         {
  32.             [JsonProperty("id")]
  33.             public int UserID { get; set; }
  34.             [JsonProperty("name")]
  35.             public string UserName { get; set; }
  36.             [JsonProperty("lang")]
  37.             public string LangCode { get; set; }
  38.         }
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement