<tfoot id='1z75U'></tfoot>

      <bdo id='1z75U'></bdo><ul id='1z75U'></ul>

      <small id='1z75U'></small><noframes id='1z75U'>

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

      1. <legend id='1z75U'><style id='1z75U'><dir id='1z75U'><q id='1z75U'></q></dir></style></legend>
      2. 无法将当前 JSON 对象(例如 {“name":“value&qu

        时间:2023-08-23

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

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

              <tbody id='kXxN7'></tbody>
              <bdo id='kXxN7'></bdo><ul id='kXxN7'></ul>

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

                1. 本文介绍了无法将当前 JSON 对象(例如 {“name":“value"})反序列化为“System.Collections.Generic.List"类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  使用系统;使用 System.Collections.Generic;使用 System.Linq;使用 System.Text;使用脸书;使用 Newtonsoft.Json;命名空间脸书{课堂节目{静态无效主要(字符串 [] 参数){var client = new FacebookClient(acc_ess);动态结果 = client.Get("fql", new { q = "select target_id,target_type from connection where source_id = me()"});字符串 jsonstring = JsonConvert.SerializeObject(result);//jsonstring {"data":[{"target_id":9503123,"target_type":"user"}]}列出<根对象>datalist = JsonConvert.DeserializeObject<List<RootObject>>(jsonstring);}公共类基准{公共 Int64 target_id { 获取;放;}公共字符串目标类型 { 获取;放;}}公共类 RootObject{公共列表<基准>数据{得到;放;}}}}

                  <块引用>

                  无法反序列化当前 JSON 对象(例如 {"name":"value"})输入类型'System.Collections.Generic.List`1[facebook.Program+RootObject]'因为该类型需要一个 JSON 数组(例如 [1,2,3])来反序列化正确.要修复此错误,请将 JSON 更改为 JSON 数组(例如 [1,2,3])或更改反序列化类型,使其成为正常的.NET 类型(例如,不是像整数这样的原始类型,也不是集合类型如数组或列表)可以是

                  我看了其他帖子.

                  我的 json 看起来像这样:

                  {"data":[{"target_id":9503123,"target_type":"user"}]}

                  解决方案

                  为了明确,除了@SLaks 的回答,这意味着你需要改变这一行:

                  Listdatalist = JsonConvert.DeserializeObject<List<RootObject>>(jsonstring);

                  到这样的事情:

                  RootObject datalist = JsonConvert.DeserializeObject(jsonstring);

                  using System;
                  using System.Collections.Generic;
                  using System.Linq;
                  using System.Text;
                  using Facebook;
                  using Newtonsoft.Json;
                  
                  namespace facebook
                  {
                      class Program
                      {
                          static void Main(string[] args)
                          {
                              var client = new FacebookClient(acc_ess);
                              dynamic result = client.Get("fql", new { q = "select target_id,target_type from connection where source_id = me()"});
                              string jsonstring = JsonConvert.SerializeObject(result);
                  
                              //jsonstring {"data":[{"target_id":9503123,"target_type":"user"}]}
                              List<RootObject> datalist = JsonConvert.DeserializeObject<List<RootObject>>(jsonstring);
                          }
                  
                          public class Datum
                          {
                              public Int64 target_id { get; set; }
                              public string target_type { get; set; }
                          }
                  
                          public class RootObject
                          {          
                              public List<Datum> data { get; set; }
                          }
                      }
                  }
                  

                  Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[facebook.Program+RootObject]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be

                  I looked at other posts.

                  My json looks like this:

                  {"data":[{"target_id":9503123,"target_type":"user"}]}
                  

                  解决方案

                  To make it clear, in addition to @SLaks' answer, that meant you need to change this line :

                  List<RootObject> datalist = JsonConvert.DeserializeObject<List<RootObject>>(jsonstring);
                  

                  to something like this :

                  RootObject datalist = JsonConvert.DeserializeObject<RootObject>(jsonstring);
                  

                  这篇关于无法将当前 JSON 对象(例如 {“name":“value"})反序列化为“System.Collections.Generic.List"类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 .NET 中解析大型 JSON 文件 下一篇:如何在 json 反序列化期间忽略未知的枚举值?

                  相关文章

                  最新文章

                  <legend id='xQYP3'><style id='xQYP3'><dir id='xQYP3'><q id='xQYP3'></q></dir></style></legend>
                2. <tfoot id='xQYP3'></tfoot>

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

                    1. <small id='xQYP3'></small><noframes id='xQYP3'>

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