本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.Clear方法的具体用法?C# JArray.Clear怎么用?C# JArray.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JArray
的用法示例。
在下文中一共展示了JArray.Clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Clear
public void Clear()
{
JArray a = new JArray {1};
Assert.AreEqual(1, a.Count);
a.Clear();
Assert.AreEqual(0, a.Count);
}
示例2: Main
static void Main(string[] args)
{
//so you can send the request over HTTP
WebClient webClient = new WebClient();
//Your API variables to send the request
string base_url = "https://maps.googleapis.com/maps/api/geocode/json?";
string latlng = null;
string api_key = "your key here";
string full_query = null;
////read the excel file and place the required columns into a List creating one object per row
//List<Club> clubs = new List<Club>();
//MyExcel.InitializeExcel();
//clubs = MyExcel.ReadMyExcel();
//foreach (var club in clubs)
//{
// //here we want to assemble the request sent to the Google Maps API
// latlng = "latlng=" + club.Lat + "," + club.Long + "&";
// full_query = webClient.DownloadString(base_url + latlng + api_key);
// dynamic json = JsonConvert.DeserializeObject(full_query);
// string fileName = club.Competitor_Key + ".txt";
// //place each response into a separate file with the filename as the competitor key found in the excel input file
// System.IO.File.WriteAllText(@"your path here" + fileName, json.ToString());
//}
//loop through the files in the folder you just dropped off the json response files into:
string[] files = Directory.GetFiles(@"your path here");
string competitorKey;
foreach (string file in files)
{
try
{ //open a Streamreader to read the file from beginning to end
using (StreamReader sr = new StreamReader(file))
{
// read the file to the very end and store it as a string
String json_response = sr.ReadToEnd();
// parse the response into a json object
JObject results = JObject.Parse(json_response);
// create a json array to store the tokens found in the 'results' object
JArray competitor_address = new JArray();
// create a string to store the instance of the json array element we want
string fullAddress = null;
// loop through the different tokens putting each token into 'competitor_address' jarray
// assign the address we want to the 'fullAddress' string variable
foreach (var result in results["results"])
{
competitor_address.Add(result["formatted_address"]);
fullAddress = (string) competitor_address[0];
}
//write 'fullAddress' to a file
//the 'using' statement allows you to append to the same file
//clear the 'competitor_address' jarray to ensure you grab the
//full address of each file only
using (System.IO.StreamWriter output =
new System.IO.StreamWriter(@"your path here", true))
{
competitorKey = Path.GetFileName(file);
output.WriteLine(competitorKey + "; " + fullAddress + ";");
competitor_address.Clear();
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
}
}
示例3: UploadPlaylist
/// <summary>
/// Uploads a playlist to the cloud.
/// </summary>
/// <param name="playlist">The playlist to upload</param>
private static void UploadPlaylist(PlaylistData playlist)
{
if (playlist == null) return;
JArray tracks = new JArray();
while (true)
{
try
{
tracks.Clear();
foreach (var track in playlist.Tracks)
{
var t = TrackToJSON(track);
if (t != null)
tracks.Add(t);
}
break;
}
catch { }
}
JObject para = new JObject();
para["name"] = playlist.Name;
para["is_public"] = "0";
para["songs"] = tracks;
lock (syncOutLocker)
syncOutBuffer.Add(new SyncOperation("create", "playlists", para));
InitiateSyncTimer();
}
示例4: GenerateEdgeViewJSON
/// <summary>
/// Generates an json edge view.
/// </summary>
/// <param name="aEdge">The edge.</param>
/// <returns>An jarray contains the json edge view.</returns>
private JArray GenerateEdgeViewJSON(IEdgeView aEdge)
{
JArray Output = new JArray();
#region Edge Properties
foreach (var _property in aEdge.GetAllProperties())
{
JProperty _newEdge = null;
if (_property.Item2 == null)
{
_newEdge = new JProperty(_property.Item1, "");
}
else
{
if (_property.Item2 is Stream)
{
_newEdge = new JProperty(_property.Item1, "BinaryProperty");
}
else
{
if (_property.Item2 is ICollectionWrapper)
{
_newEdge = new JProperty(_property.Item1, HandleListProperties((ICollectionWrapper)_property.Item2));
}
else
{
_newEdge = new JProperty(_property.Item1, _property.Item2.ToString());
}
}
}
Output.Add(new JObject(new JProperty("Properties", new JObject(_newEdge))));
}
#endregion
if (aEdge is IHyperEdgeView)
{
var edgeProperties = new JArray();
foreach (var singleEdge in ((IHyperEdgeView)aEdge).GetAllEdges())
{
foreach (var singleEdgeProp in singleEdge.GetAllProperties())
{
if (singleEdgeProp.Item2 is ICollectionWrapper)
{
edgeProperties.Add(new JObject(new JProperty(singleEdgeProp.Item1, HandleListProperties((ICollectionWrapper)singleEdgeProp.Item2))));
}
else
{
edgeProperties.Add(new JObject(new JProperty(singleEdgeProp.Item1, singleEdgeProp.Item2.ToString())));
}
}
Output.Add(new JObject(new JProperty("SingleEdge", new JObject(new JProperty("Properties", new JArray(edgeProperties))), new JObject(new JProperty("TargetVertex", GenerateVertexViewJSON(singleEdge.GetTargetVertex()))))));
edgeProperties.Clear();
}
}
else
{
Output.Add(new JObject(new JProperty("TargetVertex", GenerateVertexViewJSON(((ISingleEdgeView)aEdge).GetTargetVertex()))));
}
return Output;
}