当前位置: 首页>>代码示例>>C#>>正文


C# JArray.Clear方法代码示例

本文整理汇总了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);
    }
开发者ID:nagyist,项目名称:Newtonsoft.Json,代码行数:8,代码来源:JArrayTests.cs

示例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);
                }
            }
        }
开发者ID:mashhype,项目名称:APIParsers,代码行数:73,代码来源:Program.cs

示例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();
        }
开发者ID:uQr,项目名称:stoffi,代码行数:35,代码来源:ServiceManager.cs

示例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;
        }
开发者ID:loubo,项目名称:sones,代码行数:73,代码来源:JSON_IO.cs


注:本文中的Newtonsoft.Json.Linq.JArray.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。