使用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; }
}
}
}