Newtonsoft.Json.JsonConvert.SerializeObject()
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json

·
C# Newtonsoft.Json.JsonConvert.SerializeObject() 参数Newtonsoft.Json.Formatting.Indented与不带参数的区别。
Newtonsoft.Json.JsonConvert.SerializeObject()这个函数返回一个JSON字符串。
默认的,参数是None,如果加了Newtonsoft.Json.Formatting.Indented,会返回标准的格式化后的JSON字符串。
写了个小Demo测试了一携带参数和不带参数的区别
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
namespace Demo
{
class Person
{
public string name = null;
public string age = null;
}
class MainClass
{
public static void Main(string[] args)
{
Person p1 = new Person();
p1.name = "name1";
p1.age = "age1";
Person p2 = new Person();
p2.name = "name2";
p2.age = "age2";
string JSON = Newtonsoft.Json.JsonConvert.SerializeObject(p1, Newtonsoft.Json.Formatting.Indented);
Console.WriteLine(JSON);
string JSON1 = Newtonsoft.Json.JsonConvert.SerializeObject(p2);
Console.WriteLine(JSON1);
}
}
}
打印结果如下:
{
"name": "name1",
"age": "age1"
}
{"name":"name2","age":"age2"}
Newtonsoft.Json.Formatting.Indented 表示 ”缩进“,即返回前面的打印结果。默认是返回后面的打印结果。




适用于现代 C++ 的 JSON。
最近提交(Master分支:6 个月前 )
51a77f1d
2 天前
756ca22e
2 天前
更多推荐
所有评论(0)