當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。