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


C# JValue.GetType方法代码示例

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


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

示例1: convertJvalueToType

 private object convertJvalueToType(JValue jv, Type t)
 {
     MethodInfo mi = jv.GetType().GetMethod("ToObject", new Type[] { });
     MethodInfo gmi = mi.MakeGenericMethod(t);
     return gmi.Invoke(jv, new object[] { });
 }
开发者ID:kumait,项目名称:HXF.net,代码行数:6,代码来源:HxfHandler.cs

示例2: webClient_OpenReadCompleted

        void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
        {
            try
            {
                using (var reader = new StreamReader(e.Result))
                {
                    String json = reader.ReadToEnd();
                    JObject o = JObject.Parse(json);
                    Menu.Venue[] tempVens = new Menu.Venue[30];
                    int i = 0;

                    if (o[meal.Text.ToUpper()] != null && o[meal.Text.ToUpper()].HasValues)
                        foreach (JToken venue in o[meal.Text.ToUpper()].Children())
                        {
                            Menu.Venue.Dish[] tempDishes = new Menu.Venue.Dish[60];
                            String temp = venue.ToString().Substring(1, 40);
                            String venName = temp.Remove(temp.IndexOf("\""));
                            int j = 0;
                            foreach (JToken dish in venue.Children().Children())
                            {
                                bool ovolacto, vegan, halal, passover, hasNutrition;

                                String name = (String)dish["name"];

                                String ovo = (String)dish["ovolacto"];
                                if (ovo.Equals("true"))
                                    ovolacto = true;
                                else
                                    ovolacto = false;

                                String veg = (String)dish["vegan"];
                                if (veg.Equals("true"))
                                    vegan = true;
                                else
                                    vegan = false;

                                String passO = (String)dish["passover"];
                                if (passO.Equals("true"))
                                    passover = true;
                                else
                                    passover = false;

                                String hal = (String)dish["halal"];
                                if (hal.Equals("true"))
                                    halal = true;
                                else
                                    halal = false;

                                Newtonsoft.Json.Linq.JValue dummy = new Newtonsoft.Json.Linq.JValue(false);
                                if (dummy.GetType().FullName.Equals(dish["nutrition"].GetType().FullName))
                                {
                                    hasNutrition = false;
                                    tempDishes[j++] = new Menu.Venue.Dish(name, hasNutrition, ovolacto, vegan, passover, halal);
                                }
                                else
                                {
                                    hasNutrition = true;
                                    float[] nutrition = new float[20];
                                    int k = 0;
                                    foreach (JToken child in dish["nutrition"])
                                        nutrition[k++] = (float)child;
                                    tempDishes[j++] = new Menu.Venue.Dish(name, hasNutrition, ovolacto, vegan, passover, halal, nutrition);
                                }

                            }
                            tempVens[i++] = new Menu.Venue(venName, tempDishes); ;
                        }
                    else
                        listBox.Items.Add(new Menu.Venue("No menu available \nfor selected meal", null));
                    menu = new Menu(tempVens);
                }
                textBlock1.Visibility = Visibility.Collapsed;
                if ((App.Current as App).ovoFilter)
                {
                    foreach (Menu.Venue ven in menu.venues)
                        if (ven != null)
                        {
                            bool added = false;
                            listBox.Items.Add(ven);
                            foreach (Menu.Venue.Dish dish in ven.dishes)
                                if (dish != null && (dish.ovolacto || dish.vegan))
                                {
                                    listBox.Items.Add(dish);
                                    added = true;
                                }
                            if (!added)
                                listBox.Items.Remove(ven);
                            else
                                listBox.Items.Add(new Menu.Venue("\t", null));
                        }
                }
                else if ((App.Current as App).veganFilter)
                {
                    foreach (Menu.Venue ven in menu.venues)
                        if (ven != null)
                        {
                            bool added = false;
                            listBox.Items.Add(ven);
                            foreach (Menu.Venue.Dish dish in ven.dishes)
                                if (dish != null && (dish.vegan))
//.........这里部分代码省略.........
开发者ID:tremblay,项目名称:Grinnell-Menu-WP,代码行数:101,代码来源:VenuesPage.xaml.cs

示例3: Transform

 public static IExpressionConstant Transform(JValue obj)
 {
     // TODO: make this do something
     //var val = obj.Value;
     if (obj.Type.Equals(JTokenType.Integer)) 
     {
         return NumericValue.Create(obj.ToObject<int>());
     } 
     else if (obj.Type.Equals(JTokenType.Float))
     {
         return NumericValue.Create(obj.ToObject<decimal>());
     }
     else if (obj.Type.Equals(JTokenType.String))
     {
         return new StringValue(obj.ToObject<String>());
     }
     else if (obj.Type.Equals(JTokenType.Boolean))
     {
         return new BooleanValue(obj.ToObject<bool>());
     }
     else if (obj.Type.Equals(JTokenType.Null))
     {
         //throw new ApplicationException("NULL Not implemented yet");
         return null; // TODO: Change this to an option
     }
     else
     {
         throw new Exception("Don't know how to transform a " +obj.GetType()+ ".");
     }
 }
开发者ID:gitter-badger,项目名称:Liquid.NET,代码行数:30,代码来源:DictionaryFactory.cs


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