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


C# IRequest.GetJSON方法代码示例

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


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

示例1: Get

        public static Backpack Get(IRequest request, bool cache=true, String profileID=null)
        {
            //get the json
            String raw = request.GetJSON();
            if(cache)
                Cache.SaveJSON(String.Format("backpack{0}.txt", profileID ?? ""), raw);
            JToken json = JObject.Parse(raw)["result"];

            //parse it
            int result = json["status"].ToObject<int>();

            if (result != 1)
            {
                if (result == 8)
                    throw new ArgumentException("SteamID invalid");
                if (result == 15)
                    throw new InvalidOperationException("Backpack was private");
                if (result == 18)
                    throw new ArgumentException("SteamID does not exist");
            }

            Backpack backpack = new Backpack(json["num_backpack_slots"].ToObject<int>());
            //parse all the items
            List<Item> items = ParseItems(json["items"]);

            //place the items in the backpack
            foreach (Item i in items)
            {
                if (i.IsPlaced)
                    backpack.ItemsAsPlaced[i.Position - 1] = i;
                else
                    backpack.UnplacedItems.Add(i);
            }
            return backpack;
        }
开发者ID:TheCommieDuck,项目名称:SharpTF2,代码行数:35,代码来源:Backpack.cs

示例2: Get

        public static ItemSchema Get(IRequest request, bool cache=true)
        {
            //get the json
            String raw = request.GetJSON();
            if(cache)
                Cache.SaveJSON("schema.txt", raw);

            JToken json = JObject.Parse(raw)["result"];
            ItemSchema schema = new ItemSchema();

            foreach (JToken item in json["items"])
            {
                ItemTemplate template = new ItemTemplate();
                template.Name = item["item_name"].ToObject<String>();
                int defIndex = item["defindex"].ToObject<int>();

                if (template.Name.StartsWith("Strange Part:") || template.Name.StartsWith("Strange Cosmetic Part:"))
                {
                    int id = item["attributes"][0]["value"].ToObject<int>();
                    schema.StrangePartIDs.Add(id, defIndex);
                    schema.StrangePartNames.Add(id, template.Name.Substring(template.Name.IndexOf(':')+2));
                }

                String type = item["item_slot"] == null ? "other" : item["item_slot"].ToObject<String>();
                switch (type)
                {
                    //weapons!
                    case "primary":
                    case "secondary":
                    case "melee":
                    case "pda":
                    case "pda2":
                    case "building":
                        template.Type = ItemType.Weapon;
                        //if it's got the same values, then add it to the vintage chart (we can safely ignore basically everything else)
                        //of course, this does give a few things that you can't get in vintage or is entirely pointless, but *shrug*
                        if (item["min_ilevel"].ToObject<int>() == item["max_ilevel"].ToObject<int>())
                            schema.DefaultVintageLevels.Add(defIndex, item["min_ilevel"].ToObject<int>());
                        break;
                    case "head":
                    case "misc":
                        template.Type = ItemType.Cosmetic;
                        break;
                    default:
                        template.Type = ItemType.Tool;
                        break;
                }
                schema.Items.Add(defIndex, template);
            }
            return schema;
        }
开发者ID:TheCommieDuck,项目名称:SharpTF2,代码行数:51,代码来源:ItemSchema.cs

示例3: Get

        public static PriceSchema Get(IRequest request, bool cache=true)
        {
            //get the json
            String raw = request.GetJSON();

            dynamic fullJson = JsonConvert.DeserializeObject(raw);
            if (fullJson.success == 0)
                return null;
            if (cache)
                Cache.SaveJSON("backpacktf.txt", raw);
            dynamic json = fullJson.response;

            PriceSchema schema = new PriceSchema();

            //first, get the raw prices of buds/keys/ref.
            Price.RefPrice = json.raw_usd_value;
            Price.KeyPrice = json.items["Mann Co. Supply Crate Key"]["prices"]["6"]["Tradable"]
                ["Craftable"][0]["value_raw"];
            Price.BudsPrice = json["items"]["Earbuds"]["prices"]["6"]["Tradable"]["Craftable"][0]["value_raw"];

            foreach (dynamic item in json.items)
            {
                //we don't want Australium Gold
                bool isAus = item.Name.StartsWith("Australium") && !item.Name.Contains("Gold");
                if (item.Value.defindex.Count == 0)
                {
                    Console.WriteLine("Found an item with no defindex");
                    continue;
                }

                //it's changed - now defindices are defindex: [val]
                int defIndex = (int)item.Value.defindex[0].Value;
                //and now iterate all the qualities
                foreach (dynamic itemQuality in item.Value.prices)
                {
                    Quality quality = (Quality)Enum.Parse(typeof(Quality), itemQuality.Name);
                    foreach (dynamic tradableItem in itemQuality.Value)
                    {
                        //tradables, craftables
                        bool isTradable = (tradableItem.Name == "Tradable");
                        foreach (dynamic craftableItem in tradableItem.Value)
                        {
                            bool isCraftable = (craftableItem.Name == "Craftable");

                            //it's now split into some things being Craftability: [blah blah] and some being Craftability: attribute value : blah blah
                            //this is 0 for most things, but some things like unusuals and crates have values
                            foreach (dynamic attributes in craftableItem.Value)
                            {
                                //ignore it if it's 0.
                                bool isNested = !(craftableItem.Value is JArray);
                                int series = isNested ? Convert.ToInt32(attributes.Name) : 0;
                                dynamic priceObject = isNested ? attributes.Value : attributes;

                                Price price = new Price();
                                double lowPrice = priceObject["value"].Value;
                                double highPrice = priceObject["value_high"] == null ? lowPrice : priceObject["value_high"].Value;

                                String currency = priceObject["currency"].Value;

                                //normalise to refined
                                if (currency == "earbuds")
                                {
                                    lowPrice *= Price.BudsPrice;
                                    highPrice *= Price.BudsPrice;
                                }
                                else if (currency == "keys")
                                {
                                    lowPrice *= Price.KeyPrice;
                                    highPrice *= Price.KeyPrice;
                                }
                                else if (currency == "usd")
                                {
                                    lowPrice *= Price.RefPrice;
                                    highPrice *= Price.RefPrice;
                                }
                                price.LowRefPrice = lowPrice;
                                price.HighRefPrice = highPrice;

                                //separate australiums, unusuals/crates, and the other one
                                schema.PriceList[GetItemKey(quality, defIndex, isTradable, isCraftable, isAus, series)] = price;
                            }
                        }
                    }
                }
            }
            return schema;
        }
开发者ID:TheCommieDuck,项目名称:SharpTF2,代码行数:87,代码来源:PriceSchema.cs


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