我有下一个JSON:
{
"Atrrib1":"Value1",
"Legs":[
{
"InternalAttrib1":"Value2",
"InternalAttrib2":"Value3",
"InternalDate":"2014-10-01T00:00:00Z"
},
{
"InternalAttrib1":"Value4",
"InternalAttrib2":"Value5",
"InternalDate":"2014-10-01T00:00:00Z"
}
]
}
我有一个设置日期的功能,如果我想更改例如“Attrib1”,我就这样做了:
public JObject FixAtribb1(JObject request)
{
request["Attrib1"] = "SomeValue";
return request;
}
但是当我尝试为“InternalDate”做同样的事情时,它不起作用并在原始JSON中创建另一个attrib:
request[@"Legs[" + legCount + "].InternalDate"] = DateTime.UtcNow;
如何以与“Attrib1”相同的方式为“InternalDate”赋值?
答案 0 :(得分:0)
你需要的就是这样的东西
request["Legs"][legCount]["InternalDate"] =DateTime.UtcNow;
您甚至可以使用dynamic
关键字
dynamic dyn = request;
dyn.Legs[0].InternalDate = DateTime.UtcNow;