JToken el={"count_data": {
"20140903": 8,
"20140905": 4,
"20140918": 12
}}
el.AddAfterSelf(new JToken("{\"count\":2}"))
我想添加"计数"现有的JToken。
答案 0 :(得分:0)
JToken el = {“count_data”:{ “20140903”:8, “20140905”:4, “20140918”:12 }}
foreach (var a in ((Newtonsoft.Json.Linq.JProperty)(el)))
{
int i = 0;
foreach (var value in ((Newtonsoft.Json.Linq.JObject)(a)))
{
i = i + Convert.ToInt32(value.Value);
Console.WriteLine(value.Value);
}
if (i != 0)
{
el.Parent["count"] = i;
}
else {
el.Parent["count"] = 0;
}
}