Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- namespace JsonTestApp
- {
- class Program
- {
- static void Main(string[] args)
- {
- var data = new UserModel();
- data.UserID = 100;
- data.UserName = "太郎";
- data.LangCode = "ja";
- using (var jsonWrite = new StreamWriter("test.json"))
- {
- var serialize = JsonConvert.SerializeObject(data);
- jsonWrite.WriteLine(serialize);
- }
- }
- [JsonObject("user")]
- public class UserModel
- {
- [JsonProperty("id")]
- public int UserID { get; set; }
- [JsonProperty("name")]
- public string UserName { get; set; }
- [JsonProperty("lang")]
- public string LangCode { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement