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


C# JsonSerializer.DeserializeFromReader方法代码示例

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


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

示例1: Report

        public ContentResult Report()
        {
            var s = new JsonSerializer<List<ConnectionStringConfig>>();

            var x = s.DeserializeFromReader(new StreamReader(HttpContext.Server.MapPath("../json") +  "\\" + "ConnectionStrings.json"));
            var reportConfig = new SqlReportConfig { ReportTemplateRoot = HttpContext.Server.MapPath("../sql") + "\\", ReportName = "employeeList", ConnectionString = "Data Source=CORPSPLRPTDB1;Initial Catalog=ApplicationLog;Persist Security Info=True;Trusted_Connection=True;" };
            var jsonHtmlTableGenerator = new JsonHtmlTableGenerator(reportConfig);
            var jsonHtmlTable = jsonHtmlTableGenerator.GetJsonTable(JsonHtmlTableType.DataTables);

            return new ContentResult { Content = jsonHtmlTable, ContentType = "application/json" };
        }
开发者ID:adamjmoon,项目名称:JsonHtml,代码行数:11,代码来源:HomeController.cs

示例2: AssociateDiskAsync

        public async Task AssociateDiskAsync(DiskViewModel diskView)
        {
            DiskRecord resp;
            try
            {
                resp = await _serviceClient.GetAsync(new GetDiskInfo { DiskName = diskView.Name });
            }
            catch (WebServiceException e)
            {
                if (e.StatusCode == 404)
                {
                    resp = null;
                }
                else
                {
                    throw;
                }
            }

            var capacity = diskView.Disk.Capacity;
            diskView.SynchronizingDisk.ServerAssociation = diskView.Name;
            var oldNotificationDispatcher = diskView.Disk.NotificationDispatcher;

            if (resp == null)
            {
                // need to upload the disk first
                StatusText = String.Format("Disk {0} is being uploaded to the server. Please wait...", diskView.Name);
                try
                {
                    diskView.SynchronizingDisk.NotifySynchronized();
                    diskView.Disk.Dispose();
                    // ReSharper disable AssignNullToNotNullAttribute
                    diskView.Disk = null;
                    // ReSharper restore AssignNullToNotNullAttribute

                    using (var fs = new FileStream(diskView.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                    {
                        var request = new UploadDisk
                            {
                                Capacity = capacity,
                                DiskName = diskView.Name,
                                RequestStream = fs
                            };
                        var requestUrl = String.Format("{0}{1}?Capacity={2}", _serverUrl,
                            request.ToUrl("PUT").Substring(1), capacity);

                        //resp = await _serviceClient.PutAsync(request);
                        var req = WebRequest.CreateHttp(requestUrl);
                        req.Method = "PUT";
                        req.Accept = "application/json";

                        var reqStr = await req.GetRequestStreamAsync();
                        await fs.CopyToAsync(reqStr);
                        var rawResp = await req.GetResponseAsync();
                        var responseStream = rawResp.GetResponseStream();
                        if (responseStream != null)
                        {
                            using (var respReader = new StreamReader(responseStream, Encoding.UTF8))
                            {
                                var s = new JsonSerializer<DiskRecord>();
                                resp = s.DeserializeFromReader(respReader);
                            }
                        }
                        else
                        {
                            throw new InvalidOperationException("Missing response from upload.");
                        }

                        StatusText = string.Format("Disk {0} successfully uploaded to server.", diskView.Name);
                        await RefreshServerDisksAsync(suppressStatusMessage: true);
                    }
                }
                finally
                {
                    diskView.Disk = VirtualDisk.OpenExisting(diskView.FileName);
                    diskView.Disk.NotificationDispatcher = oldNotificationDispatcher;
                }
            }
            StatusText = String.Format("Disk {0} associated with server as {1}.", diskView.Name, resp.Name);
        }
开发者ID:RainsSoft,项目名称:panda,代码行数:80,代码来源:BrowserViewModel.cs

示例3: LoadModelAsync

        private Task<MusicModel> LoadModelAsync()
        {
            var t1 = new Task<MusicModel>(() =>
            {
                Busy = true;
                MusicModel musicModel;
                if (File.Exists(StorageFileLocation))
                {
                    using (var reader = new StreamReader(StorageFileLocation))
                    {
                        var serializer = new JsonSerializer<MusicModel>();
                        musicModel = serializer.DeserializeFromReader(reader);
                    }
                }
                else
                {
                    musicModel = new MusicModel(MusicLocation, MusicDestination);
                }

                return musicModel;
            });

            t1.Start();
            return t1;
        }
开发者ID:dmacuk,项目名称:MusicPicker,代码行数:25,代码来源:MusicViewModel.cs

示例4: ConnectionStrings

        private List<ConnectionStringConfig> ConnectionStrings()
        {
            using(var reader = new StreamReader(BaseReportConfig().ReportTemplateRoot.Replace("sql", "json") + "ConnectionStrings.json"))
            {
                var serializer = new JsonSerializer<List<ConnectionStringConfig>>();
                var connectionStrings = serializer.DeserializeFromReader(reader);
                System.Web.HttpContext.Current.Cache.Insert("ConnectionStrings", connectionStrings);

                return connectionStrings;
            }
        }
开发者ID:adamjmoon,项目名称:JsonHtml,代码行数:11,代码来源:ReportController.cs


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