我试图序列化一些的JSON API调用:C#JSON匿名系列化
string f5Name = "MyBigIpName";
string poolName = "myPoolName";
string postJson2 = JsonConvert.SerializeObject(
new
{
f5 = new {
f5Name = new {
poolName = memberState
},
}
}
);
这将导致以下JSON:
{
"f5": {
"f5Name": {
"poolName": {
"member": {
"address": "10.0.0.0",
"port": 80
},
"session_state": "STATE_DISABLED"
}
}
}
}
不过,我是什么真正想要做的是产生这个JSON:
{
"f5": {
"MyBigIpName": {
"myPoolName": {
"member": {
"address": "10.0.0.0",
"port": 80
},
"session_state": "STATE_DISABLED"
}
}
}
}
有什么办法让f5Name和poolName属性名称是动态的,这样我就可以产生上面的JSON?我使用Newtonsoft.JSON(JSON.NET)