<legend id='g5vgi'><style id='g5vgi'><dir id='g5vgi'><q id='g5vgi'></q></dir></style></legend>

      <i id='g5vgi'><tr id='g5vgi'><dt id='g5vgi'><q id='g5vgi'><span id='g5vgi'><b id='g5vgi'><form id='g5vgi'><ins id='g5vgi'></ins><ul id='g5vgi'></ul><sub id='g5vgi'></sub></form><legend id='g5vgi'></legend><bdo id='g5vgi'><pre id='g5vgi'><center id='g5vgi'></center></pre></bdo></b><th id='g5vgi'></th></span></q></dt></tr></i><div id='g5vgi'><tfoot id='g5vgi'></tfoot><dl id='g5vgi'><fieldset id='g5vgi'></fieldset></dl></div>
      • <bdo id='g5vgi'></bdo><ul id='g5vgi'></ul>

        <small id='g5vgi'></small><noframes id='g5vgi'>

        <tfoot id='g5vgi'></tfoot>

        Json.NET 可以对流进行序列化/反序列化吗?

        时间:2023-08-23

          <small id='nPqPs'></small><noframes id='nPqPs'>

              <i id='nPqPs'><tr id='nPqPs'><dt id='nPqPs'><q id='nPqPs'><span id='nPqPs'><b id='nPqPs'><form id='nPqPs'><ins id='nPqPs'></ins><ul id='nPqPs'></ul><sub id='nPqPs'></sub></form><legend id='nPqPs'></legend><bdo id='nPqPs'><pre id='nPqPs'><center id='nPqPs'></center></pre></bdo></b><th id='nPqPs'></th></span></q></dt></tr></i><div id='nPqPs'><tfoot id='nPqPs'></tfoot><dl id='nPqPs'><fieldset id='nPqPs'></fieldset></dl></div>
            1. <legend id='nPqPs'><style id='nPqPs'><dir id='nPqPs'><q id='nPqPs'></q></dir></style></legend>
                  <tbody id='nPqPs'></tbody>
              • <tfoot id='nPqPs'></tfoot>
                • <bdo id='nPqPs'></bdo><ul id='nPqPs'></ul>
                  本文介绍了Json.NET 可以对流进行序列化/反序列化吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  听说Json.NET比DataContractJsonSerializer快,想试一试……

                  I have heard that Json.NET is faster than DataContractJsonSerializer, and wanted to give it a try...

                  但我在 JsonConvert 上找不到任何采用流而不是字符串的方法.

                  But I couldn't find any methods on JsonConvert that take a stream rather than a string.

                  以在WinPhone上反序列化包含JSON的文件为例,我使用以下代码将文件内容读入字符串,然后反序列化为JSON.在我的(非常临时的)测试中,它似乎比使用 DataContractJsonSerializer 直接从流中反序列化慢了大约 4 倍......

                  For deserializing a file containing JSON on WinPhone, for example, I use the following code to read the file contents into a string, and then deserialize into JSON. It appears to be about 4 times slower in my (very ad-hoc) testing than using DataContractJsonSerializer to deserialize straight from the stream...

                  // DCJS
                  DataContractJsonSerializer dc = new DataContractJsonSerializer(typeof(Constants));
                  Constants constants = (Constants)dc.ReadObject(stream);
                  
                  // JSON.NET
                  string json = new StreamReader(stream).ReadToEnd();
                  Constants constants = JsonConvert.DeserializeObject<Constants>(json);
                  

                  我做错了吗?

                  推荐答案

                  更新: 这在当前版本中不再有效,请参阅 下方获取正确答案(无需投票,这在旧版本上是正确的).

                  UPDATE: This no longer works in the current version, see below for correct answer (no need to vote down, this is correct on older versions).

                  JsonTextReader 类与 StreamReader 一起使用,或直接使用采用 StreamReaderJsonSerializer 重载:

                  Use the JsonTextReader class with a StreamReader or use the JsonSerializer overload that takes a StreamReader directly:

                  var serializer = new JsonSerializer();
                  serializer.Deserialize(streamReader);
                  

                  这篇关于Json.NET 可以对流进行序列化/反序列化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:检测反序列化对象是否缺少 Json.NET 中 JsonConvert 下一篇:在 JSON.NET 中反序列化的转换接口

                  相关文章

                  最新文章

                • <i id='btiaW'><tr id='btiaW'><dt id='btiaW'><q id='btiaW'><span id='btiaW'><b id='btiaW'><form id='btiaW'><ins id='btiaW'></ins><ul id='btiaW'></ul><sub id='btiaW'></sub></form><legend id='btiaW'></legend><bdo id='btiaW'><pre id='btiaW'><center id='btiaW'></center></pre></bdo></b><th id='btiaW'></th></span></q></dt></tr></i><div id='btiaW'><tfoot id='btiaW'></tfoot><dl id='btiaW'><fieldset id='btiaW'></fieldset></dl></div>

                • <tfoot id='btiaW'></tfoot>

                    <small id='btiaW'></small><noframes id='btiaW'>

                      <bdo id='btiaW'></bdo><ul id='btiaW'></ul>

                    1. <legend id='btiaW'><style id='btiaW'><dir id='btiaW'><q id='btiaW'></q></dir></style></legend>