本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.Remove方法的具体用法?C# JArray.Remove怎么用?C# JArray.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JArray
的用法示例。
在下文中一共展示了JArray.Remove方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remove
public void Remove()
{
JValue v = new JValue(1);
JArray j = new JArray();
j.Add(v);
Assert.AreEqual(1, j.Count);
Assert.AreEqual(false, j.Remove(new JValue(1)));
Assert.AreEqual(false, j.Remove(null));
Assert.AreEqual(true, j.Remove(v));
Assert.AreEqual(false, j.Remove(v));
Assert.AreEqual(0, j.Count);
}
示例2: RemoveArrayIfEmpty
private static void RemoveArrayIfEmpty(JArray array)
{
if (array.Count == 0)
{
if (array.Parent is JProperty && array.Parent.Parent != null)
{
array.Parent.Remove();
}
else if (array.Parent is JArray)
{
array.Remove();
}
}
}
示例3: Main
static void Main(string[] args)
{
var json = new JObject();
json.Add("id", "Luna");
json.Add("name", "Silver");
json.Add("age", 19);
//Console.WriteLine(json.ToString());
var json2 = JObject.Parse("{ id : \"Luna\" , name : \"Silver\" , age : 19 }");
json2.Add("blog", "devluna.blogspot.kr");
//Console.WriteLine(json2.ToString());
User u = new User { id = "SJ", name = "Philip", age = 25 };
var json3 = JObject.FromObject(u);
//Console.WriteLine(json3.ToString());
var json4 = JObject.FromObject(new { id = "J01", name = "June", age = 23 });
//Console.WriteLine(json4.ToString());
var json5 = JObject.Parse("{ id : \"sjy\" , name : \"seok-joon\" , age : 27 }");
json5.Add("friend1", json);
json5.Add("friend2", json2);
json5.Add("friend3", json3);
json5.Add("friend4", json4);
//Console.WriteLine(json5.ToString());
var json4_name = json4["name"];
//Console.WriteLine(json4_name);
json4.Remove("name");
//Console.WriteLine(json4.ToString());
json5.RemoveAll();
//Console.WriteLine(json5.ToString());
var jarray = new JArray();
jarray.Add(1);
jarray.Add("Luna");
jarray.Add(DateTime.Now);
//Console.WriteLine(jarray.ToString());
var jFriends = new JArray();
jFriends.Add(json);
jFriends.Add(json2);
jFriends.Add(json3);
jFriends.Add(json4);
//Console.WriteLine(jFriends.ToString());
var jarray2 = new JArray();
jarray2.Add(jarray);
jarray2.Add(jFriends);
//Console.WriteLine(jarray2.ToString());
var jf0 = jFriends[0];
//Console.WriteLine(jf0.ToString());
//foreach(JObject fElement in jFriends)
//{
// var fName = fElement["name"] ?? "<NULL>";
// Console.WriteLine(fName);
//}
jFriends.Remove(jFriends[1]);
jFriends.Remove(jFriends[2]);
//Console.WriteLine(jFriends.ToString());
json2.Add("Friends", jFriends);
Console.WriteLine(json2.ToString());
}