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


C# Script.Serialization.JavaScriptSerializer.ConvertToType方法代码示例

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


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

示例1: Deserialize

        public override object Deserialize( IDictionary<string, object> dictionary,Type type,JavaScriptSerializer serializer )
        {
            if( type == typeof( ConditionDevice ) )
            {
                var obj = new ConditionDevice();
                if( dictionary.ContainsKey( "name" ) )
                    obj.Name = serializer.ConvertToType<string>(dictionary["name"] );
                if( dictionary.ContainsKey( "value" ) )
                    obj.Value = serializer.ConvertToType<string>(dictionary["value"] );

                return obj;
            }

            return null;
        }
开发者ID:moscrif,项目名称:ide,代码行数:15,代码来源:ConditionJavaScriptConverter.cs

示例2: Deserialize

        public override object Deserialize( IDictionary<string, object> dictionary,Type type,JavaScriptSerializer serializer )
        {
            if( type == typeof( Skin ) )
            {
                var obj = new Skin();
                if( dictionary.ContainsKey( "name" ) )
                    obj.Name = serializer.ConvertToType<string>(dictionary["name"] );
                if( dictionary.ContainsKey( "resolution" ) )
                    obj.ResolutionJson = serializer.ConvertToType<string>(dictionary["resolution"] );//Resolution
                if( dictionary.ContainsKey( "theme" ) )
                    obj.Theme = serializer.ConvertToType<string>(dictionary["theme"] );
                return obj;
            }

            return null;
        }
开发者ID:moscrif,项目名称:ide,代码行数:16,代码来源:SkinJavaScriptConverter.cs

示例3: Serialize

 public override IDictionary<string, object> Serialize(
     object obj,
     JavaScriptSerializer serializer)
 {
     var dataObj = serializer.ConvertToType<oEmbed>(obj);
     if (dataObj != null)
     {
         return new Dictionary<string, object>
                    {
                        {"type", dataObj.Type.ToString().ToLower()},
                        {"version", dataObj.Version},
                        {"title", dataObj.Title},
                        {"author_name", dataObj.AuthorName},
                        {"author_url", dataObj.AuthorUrl},
                        {"provider_name", dataObj.ProviderName},
                        {"provider_url", dataObj.ProviderUrl},
                        {"cache_age", dataObj.CacheAge},
                        {"thumbnail_url", dataObj.ThumbnailUrl},
                        {"thumbnail_width", dataObj.ThumbnailWidth},
                        {"thumbnail_height", dataObj.ThumbnailHeight},
                        {"url", dataObj.Url},
                        {"width", dataObj.Width},
                        {"height", dataObj.Height},
                        {"html", dataObj.Html}
                    };
     }
     return new Dictionary<string, object>();
 }
开发者ID:cwbrandsma,项目名称:OptionStrict.oEmbed,代码行数:28,代码来源:oEmbedJavaScriptConverter.cs

示例4: Deserialize

        public override object Deserialize( IDictionary<string, object> dictionary,Type type,JavaScriptSerializer serializer )
        {
            if( type == typeof( BarierPoint ) )
            {
                var obj = new BarierPoint();
                if( dictionary.ContainsKey( "x" ) )
                    obj.X = serializer.ConvertToType<int>(
                                               dictionary["x"] );
                if( dictionary.ContainsKey( "y" ) )
                    obj.Y = serializer.ConvertToType<int>(
                                               dictionary["y"] );

                return obj;
            }

            return null;
        }
开发者ID:moscrif,项目名称:ide,代码行数:17,代码来源:BarierPointJavaScriptConverter.cs

示例5: ThrowIfNestedError

 private static void ThrowIfNestedError(object objError, JavaScriptSerializer serializer)
 {
     if (objError != null)
     {
         BrightcoveError error = serializer.ConvertToType<BrightcoveError>(objError);
         throw new BrightcoveApiException(error);
     }
 }
开发者ID:Velir,项目名称:Brightcove4net,代码行数:8,代码来源:ApiUtil.cs

示例6: Execute

        public override object Execute(Expression expression)
        {
            Type elementType = expression.GetElementType();
            IList<IQuickBloxCustomObject> customObjectsList = new List<IQuickBloxCustomObject>();
            var response = QuickBloxApiClient.GetCustomObject(sessionToken, this.Translate(expression));
            QuickBloxJsonResultWrapper deserializedObject;
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                var serializer = new JavaScriptSerializer();
                var json = reader.ReadToEnd();
                deserializedObject = (QuickBloxJsonResultWrapper)serializer.Deserialize(json, quickBloxJsonResultWrapper);
                response.Close();

                foreach (var item in deserializedObject.Items)
                {
                    IQuickBloxCustomObject inner = null;
                    try
                    {
                        inner = serializer.ConvertToType(item, elementType) as IQuickBloxCustomObject;
                        customObjectsList.Add(inner);
                    }
                    catch (InvalidOperationException ex)
                    {
                        var brokenJson = serializer.Serialize(item);
                        var errorMessage = String.Format("[QuickBlox] - Unable to deserialize to object. Type: {0} Json: {1}", elementType.FullName, brokenJson);
                        log.Warn(errorMessage, ex);
                        try
                        {

                            var brokenEvent = serializer.ConvertToType(item, typeof(BrokenEvent)) as IQuickBloxCustomObject;
                            (brokenEvent as BrokenEvent).Json = brokenJson;
                            (brokenEvent as BrokenEvent).EventType = elementType;
                            customObjectsList.Add(brokenEvent);
                        }
                        catch (Exception)
                        {
                            customObjectsList.Add(new BrokenEvent() { EventType = elementType, Json = brokenJson, Created_at = default(double) });
                        }
                        continue;
                    }
                };
                return customObjectsList;
            }
        }
开发者ID:Elders,项目名称:Experiments,代码行数:44,代码来源:QBQueryProvider.cs

示例7: Deserialize

            public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
            {
                UNote result = USTx.Project.CreateNote();
                result.Lyric = dictionary["y"] as string;
                result.NoteNum = Convert.ToInt32(dictionary["n"]);
                result.PosTick = Convert.ToInt32(dictionary["pos"]);
                result.DurTick = Convert.ToInt32(dictionary["dur"]);
                result.PitchBend.SnapFirst = Convert.ToBoolean(dictionary["pitsnap"]);

                var pho = dictionary["pho"] as ArrayList;
                result.Phonemes.Clear();
                foreach (var p in pho)
                {
                    var _p = serializer.ConvertToType<UPhoneme>(p);
                    _p.Parent = result;
                    result.Phonemes.Add(_p);
                }

                result.PitchBend.SnapFirst = Convert.ToBoolean(dictionary["pitsnap"]);
                var pit = dictionary["pit"] as ArrayList;
                var pitshape = dictionary["pitshape"] as ArrayList;
                double x = 0, y = 0;
                result.PitchBend.Points.Clear();
                for (int i = 0; i < pit.Count; i ++ )
                {
                    if (i % 2 == 0)
                        x = Convert.ToDouble(pit[i]);
                    else
                    {
                        y = Convert.ToDouble(pit[i]);
                        result.PitchBend.AddPoint(new PitchPoint(x, y,
                            (PitchPointShape)Enum.Parse(typeof(PitchPointShape), (string)pitshape[i / 2])));
                    }
                }

                if (dictionary.ContainsKey("vbr"))
                {
                    var vbr = dictionary["vbr"] as ArrayList;
                    result.Vibrato.Length = Convert.ToDouble(vbr[0]);
                    result.Vibrato.Period = Convert.ToDouble(vbr[1]);
                    result.Vibrato.Depth = Convert.ToDouble(vbr[2]);
                    result.Vibrato.In = Convert.ToDouble(vbr[3]);
                    result.Vibrato.Out = Convert.ToDouble(vbr[4]);
                    result.Vibrato.Shift = Convert.ToDouble(vbr[5]);
                    result.Vibrato.Drift = Convert.ToDouble(vbr[6]);
                }

                var exp = dictionary["exp"] as Dictionary<string, object>;
                foreach (var pair in exp)
                    result.Expressions[pair.Key].Data = pair.Value;

                return result;
            }
开发者ID:KineticIsEpic,项目名称:OpenUtau,代码行数:53,代码来源:USTx.cs

示例8: Deserialize

        public override object Deserialize( IDictionary<string, object> dictionary,Type type,JavaScriptSerializer serializer )
        {
            if( type == typeof( Device ) )
            {
                var obj = new Device();
                if( dictionary.ContainsKey( "publishDir" ) )
                    obj.Publish = serializer.ConvertToType<string>(dictionary["publishDir"] );
                if( dictionary.ContainsKey( "root" ) )
                    obj.Root = serializer.ConvertToType<string>(dictionary["root"] );
                if( dictionary.ContainsKey( "application" ) )
                    obj.Application = serializer.ConvertToType<string>(dictionary["application"] );
                if( dictionary.ContainsKey( "outputDir" ) )
                    obj.Output_Dir = serializer.ConvertToType<string>(dictionary["outputDir"] );
                if( dictionary.ContainsKey( "tempDir" ) )
                    obj.Temp = serializer.ConvertToType<string>(dictionary["tempDir"] );

                if( dictionary.ContainsKey( "facebookAppID" ) )
                    obj.FacebookAppID = serializer.ConvertToType<string>(dictionary["facebookAppID"] );

                if( dictionary.ContainsKey( "outputName" ) )
                    obj.Output_Name = serializer.ConvertToType<string>(dictionary["outputName"] );

                if( dictionary.ContainsKey( "log" ) )
                    obj.LogDebug = serializer.ConvertToType<bool>(dictionary["log"] );

                if( dictionary.ContainsKey( "applicationType" ) )
                    obj.ApplicationType = serializer.ConvertToType<string>(dictionary["applicationType"] );

             	    if( dictionary.ContainsKey( "includes" ) )
                    obj.Includes = serializer.ConvertToType<Includes>(dictionary["includes"] );
             	    //if( dictionary.ContainsKey( "publish" ) )
                  //  obj.PublishPropertisFull = serializer.ConvertToType<Moscrif.IDE.Devices.PublishProperty>(dictionary["publish"] );
             	    //if( dictionary.ContainsKey( "conditions" ) )
                  //  obj.PublishPropertisFull = serializer.ConvertToType<Moscrif.IDE.Devices.PublishProperty>(dictionary["conditions"] );
            return obj;
            }

            return null;
        }
开发者ID:moscrif,项目名称:ide,代码行数:39,代码来源:DeviceJavaScriptConverter.cs

示例9: Deserialize

        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if(type != typeof(PostBackHash) && type != typeof(List<PostBackHash>)) {
                return null;
            }

            PostBackHash hash = new PostBackHash();

            if(dictionary.ContainsKey("id")) {
                hash.ControlID = serializer.ConvertToType<String>(dictionary["id"]);
            }

            if(dictionary.ContainsKey("widgetName")) {
                hash.WidgetName = serializer.ConvertToType<String>(dictionary["widgetName"]);
            }

            if(dictionary.ContainsKey("options")) {
                hash.Options = serializer.ConvertToType<Dictionary<String, object>>(dictionary["options"]);
            }

            return hash;
        }
开发者ID:pparadis,项目名称:Brew,代码行数:22,代码来源:PostBackHashConverter.cs

示例10: DeserializeJsonAllPackagesFile

        /// <summary>
        /// Deserializes all packages and their dependencies
        /// </summary>
        /// <param name="path">String path of the all packages .json file</param>
        /// <param name="jsSerializer">Javascript deserializer instanace used for the deserialization</param>
        /// <returns>Dictionary of all packages and their dependencies</returns>
        public static Dictionary<string, string[]> DeserializeJsonAllPackagesFile(string path, JavaScriptSerializer jsSerializer)
        {
            Dictionary<string, string[]> allPackagesSerialized;

            using (var reader = new StreamReader(path))
            {
                var allPackagesFile = reader.ReadToEnd();
                var obj = jsSerializer.DeserializeObject(allPackagesFile);
                allPackagesSerialized = jsSerializer.ConvertToType<Dictionary<string, string[]>>(obj);
            }

            if(allPackagesSerialized == null)
            {
                allPackagesSerialized = new Dictionary<string, string[]>();
            }

            return allPackagesSerialized;
        }
开发者ID:huuuskyyy,项目名称:Javascript-Homeworks,代码行数:24,代码来源:JSONDeserializer.cs

示例11: Deserialize

        public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            if (dictionary == null)
                throw new ArgumentNullException("dictionary");

            if (type == typeof(DataTable))
            {
                // Create the instance to deserialize into.
                DataTable list = new DataTable();

                // Deserialize the ListItemCollection's items.
                ArrayList itemsList = (ArrayList)dictionary["Rows"];
                for (int i = 0; i < itemsList.Count; i++)
                    list.Rows.Add(serializer.ConvertToType<DataRow>(itemsList[i]));

                return list;
            }
            return null;
        }
开发者ID:tomochandv,项目名称:Test,代码行数:19,代码来源:ObjectConverter.cs

示例12: Deserialize

        public void Deserialize(IDictionary<string, object> dictionary, JavaScriptSerializer serializer)
        {
            foreach (string key in dictionary.Keys)
            {
                switch (key)
                {
                    case "error":
                        Message = dictionary[key].ToString();
                        break;

                    case "code":
                        Code = (int)dictionary[key];
                        break;

                    case "errors":
                        Errors.Clear();
                        Errors.AddRange(serializer.ConvertToType<BrightcoveNestedError[]>(dictionary[key]));
                        break;
                }
            }
        }
开发者ID:Velir,项目名称:Brightcove4net,代码行数:21,代码来源:BrightcoveNestedError.cs

示例13: Deserialize

        public void Deserialize(
            IDictionary<string, object> dictionary,
            JavaScriptSerializer serializer)
        {
            foreach (string key in dictionary.Keys)
            {
                switch (key)
                {
                    case "error":
                        ApiUtil.ThrowIfError(dictionary, key, serializer);
                        break;

                    case "id":
                        Id = Convert.ToInt64(dictionary[key]);
                        break;

                    case "captionSources": 
                        CaptionSources = serializer.ConvertToType<List<BrightcoveCaptionSource>>(dictionary[key]);
                        break;
                }
            }
        }
开发者ID:adamspicer,项目名称:.NET-MAPI-Wrapper,代码行数:22,代码来源:BrightcoveCaptioning.cs

示例14: ParseDocument

        protected override List<FeedItem> ParseDocument(Dictionary<string, object> doc)
        {
            var feedItems = new List<FeedItem>(_totalLimit);
            if (doc != null)
            {
                var serializer = new JavaScriptSerializer();
                var model = serializer.ConvertToType<Model>(doc);
                for (var i = 0; i < Math.Min(_totalLimit, model.root.data.Count); i++)
                {
                    var modelItem = model.root.data[i];
                    feedItems.Add(new FeedItem(this)
                    {
                        Published = GetPublished(modelItem.created_time),
                        Title = "Via Instagram",
                        Snippet = modelItem.caption.text,
                        ImagePreviewUri = modelItem.images.standard_resolution.url,
                        ViewUri = modelItem.link
                    });
                }
            }

            return feedItems;
        }
开发者ID:farhatexe,项目名称:super-feed,代码行数:23,代码来源:InstagramFeedModule.cs

示例15: Deserialize

        /// <summary>
        /// Deserializes the specified dictionary.
        /// </summary>
        /// <param name="dictionary">The <see cref="IDictionary{String,Object}" />.</param>
        /// <param name="serializer">The <see cref="JavaScriptSerializer" />.</param>
        public void Deserialize(IDictionary<string, object> dictionary, JavaScriptSerializer serializer)
        {
            foreach (string key in dictionary.Keys)
            {
                switch (key)
                {
                    case "error":
                        ApiUtil.ThrowIfError(dictionary, key, serializer);
                        break;

                    case "accountId":
                        AccountId = Convert.ToInt64(dictionary[key]);
                        break;

                    case "audioTracks":
                        AudioTracks = serializer.ConvertToType<List<BrightcoveAudioTrack>>(dictionary[key]);
                        break;

                    case "audioTrackIds":
                        AudioTrackIds = serializer.ConvertToType<List<long>>(dictionary[key]);
                        break;

                    case "filterTags":
                        FilterTags = serializer.ConvertToType<List<string>>(dictionary[key]);
                        break;

                    case "id":
                        Id = Convert.ToInt64(dictionary[key]);
                        break;

                    case "name":
                        Name = (string)dictionary[key];
                        break;

                    case "playlistType":
                        PlaylistType = ((string)dictionary[key]).ToBrightcoveEnum<PlaylistType>();
                        break;

                    case "referenceId":
                        ReferenceId = (string)dictionary[key];
                        break;

                    case "shortDescription":
                        ShortDescription = (string)dictionary[key];
                        break;

                    case "thumbnailURL":
                        ThumbnailUrl = (string)dictionary[key];
                        break;
                }
            }
        }
开发者ID:EMPIR,项目名称:brightcove,代码行数:57,代码来源:BrightcoveAudioTrackPlaylist.cs


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