最初,我喜欢这样的Json
{
"softwareName": "MYSOFT",
"softwareVersion": "0.4.5.9",
"TimeZone": "2017-03-01T11:30:18.764103"
}
我想在“softwareName”之前添加" status":{success:true}我已经为此做了
JObject rss = JObject.Parse(jsonString);
rss.Property("softwareName").AddBeforeSelf(new JProperty("status", "{success: true}"));
给我这样的结果
{
"status": "{success: true}",
"softwareName": "MYSOFT",
"softwareVersion": "0.4.5.9",
"TimeZone": "2017-03-01T11:30:18.764103"
}
但是,我希望得到这样的结果;
{
"status": {success: true},
"softwareName": "MYSOFT",
"softwareVersion": "0.4.5.9",
"TimeZone": "2017-03-01T11:30:18.764103"
}
即没有双引号的状态值。我怎样才能达到这个理想的效果?因为在那之后我会有如下所示的观点
但目前我喜欢这个
答案 0 :(得分:3)
你想这样做:
JObject rss = JObject.Parse(jsonString);
rss.Property("softwareName").AddBeforeSelf(new JProperty("status", JObject.Parse("{success: true}")));
基本上,在将字符串添加为属性之前,需要将字符串解析为JSON对象。
答案 1 :(得分:2)
试试这个
obj = {
"softwareName": "MYSOFT",
"softwareVersion": "0.4.5.9",
"TimeZone": "2017-03-01T11:30:18.764103"
}
var newKey = "status"
var newVal = {success : true}
obj[newKey] = newVal
它给出了
obj = {
"softwareName": "MYSOFT",
"softwareVersion": "0.4.5.9",
"TimeZone": "2017-03-01T11:30:18.764103"
"status": {success : true}
}