JSON

程序集:namespace Newtonsoft.Json

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace Newtonsoft.Json
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             Dog dog=new Dog(){Name = "小王",Age = 45,Sex = true};
14            string str= JsonConvert.SerializeObject(dog);//把对象转换成JSON格式字符串
15            Dog strJson = (Dog)JsonConvert.DeserializeObject(str, typeof(Dog));//把字符串格式转换成对象
16         }
17     }
18 
19     public class Dog
20     {
21 
22         public string Name { get; set; }
23         public bool  Sex { get; set; }
24         public byte  Age { get; set; }  
25     }
26 }
json字符串与对象的转换

 

posted on 2015-04-09 14:28  高达  阅读(109)  评论(0)    收藏  举报

导航