public void Clear() { JArray a = new JArray {1}; Assert.AreEqual(1, a.Count); a.Clear(); Assert.AreEqual(0, a.Count); }
static int Clear(IntPtr L) { try { ToLua.CheckArgsCount(L, 1); Newtonsoft.Json.Linq.JArray obj = (Newtonsoft.Json.Linq.JArray)ToLua.CheckObject <Newtonsoft.Json.Linq.JArray>(L, 1); obj.Clear(); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
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); } } }
/// <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(); }
/// <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; }