我有包含动态数据的JObject,例如:
{ "person":
{ "name": "myname",
"city":"myCity",
"dynamicUserData":{}
}
}
现在基于城市,dynamicUserData应填充来自Dictionary的值。问题是如何在dynamicUserData中添加这个字典。
代码:
var jobject=JObject.Parse(@"{ ""person"": { ""name"": ""myname"", ""city"":""myCity"",""dynamicUserData"":{}}}");
var dic=new Dictionary<string, string>();
foreach (var field in someFieldArray)
{
if (field==something)
{
dic.Add(field,somevalue);
}
}
//now here how can I put these values in dynamicUserData of the JObject?
答案 0 :(得分:1)
你应该能够毫不费力地实现这一目标。在JObject上,您可以像访问动态对象一样访问属性。所以你应该能够使用
更新属性jobject.person.dynamicUserData = new JObject(dic);
或者在JObject上,您可以使用jobject [key]
访问属性