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


C# JsonReader.Close方法代码示例

本文整理汇总了C#中Newtonsoft.Json.JsonReader.Close方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.Close方法的具体用法?C# JsonReader.Close怎么用?C# JsonReader.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.JsonReader的用法示例。


在下文中一共展示了JsonReader.Close方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getAccountBalance

        //get the current account balance for a given user
        public string getAccountBalance(string username, string apiKey, ref NotifyIcon notifyIcon)
        {
            string accountBalance = "0.0";

            try
            {
                if (String.IsNullOrEmpty(username))
                    return "";

                WebClient client = new WebClient();
                string urlFormat = "http://marketplace.envato.com/api/v1/" + username + "/" + apiKey + "/account.json";
                Uri url = new Uri(string.Format(urlFormat));
                string data = client.DownloadString(url);

                using (JsonReader reader = new JsonReader(new StringReader(data)))
                {
                    while (reader.Read())
                    {
                        //users++;
                        if ((string)reader.Value == "balance")
                        {
                            reader.Read();
                            accountBalance = (string)reader.Value;
                        }
                    }
                    reader.Close(); //close the reader object
                }
            }
            catch (WebException webex)
            {
                notifyIcon.ShowBalloonTip(180000000, "EnvatoTracker error!", "Error querying the api - invalid api key maybe?\n\nError:"+webex, ToolTipIcon.None);
            }

            return accountBalance;
        }
开发者ID:chrisfay,项目名称:EnvatoTracker,代码行数:36,代码来源:EnvatoAPI.cs

示例2: getNewSalesItemName

        //return all sales information within a 2d array of parameter/values
        //Index 0 = "item name"
        //Index 1 = "sold at"
        // array[0][0] = "orangeDream"
        // array[0][1] = "Sun Mar 29 08:09:17 +1100 2009"
        // array[1][0] = "orangeDream"
        // array[1][1] = "Sun Mar 29 08:09:17 +1100 2009"
        public ArrayList getNewSalesItemName(string username, string apiKey, int max, ref NotifyIcon notifyIcon)
        {
            ArrayList twod_salesItems = new ArrayList(); //contains only the newest items (equal to max) after sorting by date

            try
            {

                if (String.IsNullOrEmpty(username))
                    return new ArrayList();

                ArrayList tempTwod_salesItems = new ArrayList(); //stores all itemname/sold at pairs before sorting and stripping out max

                WebClient client = new WebClient();
                string urlFormat = "http://marketplace.envato.com/api/v1/" + username + "/" + apiKey + "/recent-sales.json";
                Uri url = new Uri(string.Format(urlFormat));
                string data = client.DownloadString(url);

                //when looping through each item we should compare the dates against the ones in the array
                //if a newer sale is found we replace it
                using (JsonReader reader = new JsonReader(new StringReader(data)))
                {
                    string itemName = "";
                    string soldAt = "";

                    while (reader.Read())
                    {
                        if ((string)reader.Value == "item")
                        {
                            reader.Read();
                            itemName = (string)reader.Value;
                        }

                        if ((string)reader.Value == "sold_at")
                        {
                            reader.Read();
                            soldAt = (string)reader.Value;

                            //we have both item name and sold time so add to array list
                            ArrayList tempArr = new ArrayList(); //stores the item name/sold at pairs
                            tempArr.Add(itemName);
                            tempArr.Add(soldAt);
                            tempTwod_salesItems.Add(tempArr);
                        }
                    }
                    reader.Close(); //close the reader object
                }

                //lets process through the temp 2d array and extrac the newest items up to max
                ArrayList dates = new ArrayList();
                int loop = 0;
                foreach (ArrayList arr in tempTwod_salesItems)
                {
                    if (loop < max)
                        twod_salesItems.Add(arr);
                    else
                        break;

                    loop++;
                }
            }
            catch (WebException webex)
            {
                notifyIcon.ShowBalloonTip(180000000, "EnvatoTracker error!", "Error querying the api - invalid api key maybe?\nError:" + webex, ToolTipIcon.None);
            }

            return twod_salesItems;
        }
开发者ID:chrisfay,项目名称:EnvatoTracker,代码行数:74,代码来源:EnvatoAPI.cs

示例3: isValidApiKey

        //validates the username/key combo
        //on failure we get a WebException and return false, otherwise return true
        public bool isValidApiKey(string username, string apiKey)
        {
            bool isValid = false;

            try
            {
                if (String.IsNullOrEmpty(username) || String.IsNullOrEmpty(apiKey))
                    return false;

                WebClient client = new WebClient();
                string urlFormat = "http://marketplace.envato.com/api/v1/" + username + "/" + apiKey + "/account.json";
                Uri url = new Uri(string.Format(urlFormat));
                string data = client.DownloadString(url);

                using (JsonReader reader = new JsonReader(new StringReader(data)))
                {
                    while (reader.Read())
                    {
                        //do nothing with the data
                    }
                    reader.Close(); //close the reader object
                }
                isValid = true;
            }
            catch (WebException webex)
            {
                isValid = false;
            }

            return isValid;
        }
开发者ID:chrisfay,项目名称:EnvatoTracker,代码行数:33,代码来源:EnvatoAPI.cs

示例4: getTotalSales

        //get the total number of sales from the given username
        public int getTotalSales(string username)
        {
            if (String.IsNullOrEmpty(username))
                return 0;

            WebClient client = new WebClient();
            string urlFormat = "http://marketplace.envato.com/api/v1/user:" + username + ".json";
            Uri url = new Uri(string.Format(urlFormat));
            string data = client.DownloadString(url);
            int totalSales = 0;

            using (JsonReader reader = new JsonReader(new StringReader(data)))
            {
                while (reader.Read())
                {
                    //users++;
                    if ((string)reader.Value == "sales")
                    {
                        reader.Read();
                        totalSales = int.Parse((string)reader.Value);
                    }
                }
                reader.Close(); //close the reader object
            }

            return totalSales;
        }
开发者ID:chrisfay,项目名称:EnvatoTracker,代码行数:28,代码来源:EnvatoAPI.cs


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