-Code reformat
This commit is contained in:
@@ -6,50 +6,50 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Documentation.Samples.Linq
|
||||
{
|
||||
public class ModifyJson
|
||||
{
|
||||
public void Example()
|
||||
public class ModifyJson
|
||||
{
|
||||
#region Usage
|
||||
string json = @"{
|
||||
'channel': {
|
||||
'title': 'Star Wars',
|
||||
'link': 'http://www.starwars.com',
|
||||
'description': 'Star Wars blog.',
|
||||
'obsolete': 'Obsolete value',
|
||||
'item': []
|
||||
public void Example()
|
||||
{
|
||||
#region Usage
|
||||
string json = @"{
|
||||
'channel': {
|
||||
'title': 'Star Wars',
|
||||
'link': 'http://www.starwars.com',
|
||||
'description': 'Star Wars blog.',
|
||||
'obsolete': 'Obsolete value',
|
||||
'item': []
|
||||
}
|
||||
}";
|
||||
|
||||
JObject rss = JObject.Parse(json);
|
||||
|
||||
JObject channel = (JObject)rss["channel"];
|
||||
|
||||
channel["title"] = ((string)channel["title"]).ToUpper();
|
||||
channel["description"] = ((string)channel["description"]).ToUpper();
|
||||
|
||||
channel.Property("obsolete").Remove();
|
||||
|
||||
channel.Property("description").AddAfterSelf(new JProperty("new", "New value"));
|
||||
|
||||
JArray item = (JArray)channel["item"];
|
||||
item.Add("Item 1");
|
||||
item.Add("Item 2");
|
||||
|
||||
Console.WriteLine(rss.ToString());
|
||||
// {
|
||||
// "channel": {
|
||||
// "title": "STAR WARS",
|
||||
// "link": "http://www.starwars.com",
|
||||
// "description": "STAR WARS BLOG.",
|
||||
// "new": "New value",
|
||||
// "item": [
|
||||
// "Item 1",
|
||||
// "Item 2"
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
#endregion
|
||||
}
|
||||
}";
|
||||
|
||||
JObject rss = JObject.Parse(json);
|
||||
|
||||
JObject channel = (JObject)rss["channel"];
|
||||
|
||||
channel["title"] = ((string)channel["title"]).ToUpper();
|
||||
channel["description"] = ((string)channel["description"]).ToUpper();
|
||||
|
||||
channel.Property("obsolete").Remove();
|
||||
|
||||
channel.Property("description").AddAfterSelf(new JProperty("new", "New value"));
|
||||
|
||||
JArray item = (JArray) channel["item"];
|
||||
item.Add("Item 1");
|
||||
item.Add("Item 2");
|
||||
|
||||
Console.WriteLine(rss.ToString());
|
||||
// {
|
||||
// "channel": {
|
||||
// "title": "STAR WARS",
|
||||
// "link": "http://www.starwars.com",
|
||||
// "description": "STAR WARS BLOG.",
|
||||
// "new": "New value",
|
||||
// "item": [
|
||||
// "Item 1",
|
||||
// "Item 2"
|
||||
// ]
|
||||
// }
|
||||
// }
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user