赞
踩
使用JsonConvert.SerializeObject将任意类型数值,转换JSON字符串
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Converters;
- using Newtonsoft.Json.Linq;
-
- namespace ConsoleApp1
- {
- class Program
- {
- static void Main(string[] args)
- {
- StudentInfo info = new StudentInfo();
- info.Sname = "dld";
- info.Gender = "女";
- info.Age = 33;
- //string[] a = { "1","2","3"};
- //使用方法将任意类型的数值转换为json字符串
- string str = JsonConvert.SerializeObject(info);
- Console.WriteLine(str);
- Console.ReadKey();
-
- }
- public class StudentInfo
- {
- public string Sname { get; set; }
- public string Gender { get; set; }
- public byte Age { get; set; }
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。