Reputation: 509
Initially I have Json like this
{
"softwareName": "MYSOFT",
"softwareVersion": "0.4.5.9",
"TimeZone": "2017-03-01T11:30:18.764103"
}
I want to add "status": {success: true} before “softwareName” for which I have done this
JObject rss = JObject.Parse(jsonString);
rss.Property("softwareName").AddBeforeSelf(new JProperty("status", "{success: true}"));
which give me results like this
{
"status": "{success: true}",
"softwareName": "MYSOFT",
"softwareVersion": "0.4.5.9",
"TimeZone": "2017-03-01T11:30:18.764103"
}
But, I want to get result like this;
{
"status": {success: true},
"softwareName": "MYSOFT",
"softwareVersion": "0.4.5.9",
"TimeZone": "2017-03-01T11:30:18.764103"
}
i.e status value without double quotes. How can I achieve this desired result? Because after that i'll have this view as show below
but currently I have it like this
Upvotes: 4
Views: 1530
Reputation: 10034
You want to do:
JObject rss = JObject.Parse(jsonString);
rss.Property("softwareName").AddBeforeSelf(new JProperty("status", JObject.Parse("{success: true}")));
Basically, you need to parse the string as a JSON object before adding it as property.
Upvotes: 3
Reputation: 6857
try this
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
it gives
obj = {
"softwareName": "MYSOFT",
"softwareVersion": "0.4.5.9",
"TimeZone": "2017-03-01T11:30:18.764103"
"status": {success : true}
}
Upvotes: 2