我正在使用JsonConvert.SerializeObject
方法序列化这个对象:
var objx = new JsonObject
{
["prob1"] = new JsonObject
{
["phone"] = "1019577756",
["name"] = "Jan",
["type"] = "Agent"
}
};
我正在使用这个代码:
using System.Text.Json.Nodes;
var jsonString = JsonConvert.SerializeObject(objx, Formatting.None,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
});
但我得到了这个结果:
{
"prob1":
{
"phone":
{
"_value": "1019577756",
"Value": "1019577756",
"Options": null
},
"name":
{
"_value": "Jan",
"Value": "Jan",
"Options": null
},
"type"
{
"_value": "Agent",
"Value": "Agent",
"Options": null
}
}
}
但我需要这样的:
{
"prob1":
{
"phone": "1019577756",
"name": "Jan",
"type": "Agent"
}
}
我可以用JsonSerializerSettings
,但我不知道我到底需要做什么