简体   繁体   English

无法将 JSON 数组(例如 [1,2,3])反序列化为类型“”,因为类型需要 JSON object(例如,将 {“name”} 正确地反序列化为“value”:

[英]Cannot deserialize the JSON array (e.g. [1,2,3]) into type ' ' because type requires JSON object (e.g. {“name”:“value”}) to deserialize correctly

hi im trying to download data from api and then try some linq on it but i cant even display it normaly.嗨,我试图从 api 下载数据,然后在上面尝试一些 linq,但我什至无法正常显示。 dynamic type works propelly but i cant use linq with it动态类型可以正常工作,但我不能使用 linq

im using this api http://api.nbp.pl/api/exchangerates/tables/a/?format=json我正在使用这个 api http://api.nbp.pl/api/exchangerates/tables/a/?format=json

my class in c#我在 c# 中的 class

        public class Rootobject
        {
            public Class1[] Property1 { get; set; }
        }

        public class Class1
        {
            public string table { get; set; }
            public string no { get; set; }
            public string effectiveDate { get; set; }
            public Rate[] rates { get; set; }
        }

        public class Rate
        {
            public string currency { get; set; }
            public string code { get; set; }
            public float mid { get; set; }
        }

    

the code to deserialize:反序列化的代码:

 using (WebClient client = new WebClient())
            {
                String text = Encoding.UTF8.GetString(client.DownloadData("http://api.nbp.pl/api/exchangerates/tables/a/?format=json"));
                var Data = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(text);

                Debug.WriteLine(Data);

            }

when i put it in array or list (like this)当我把它放在数组或列表中时(像这样)

var Data = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject[]>(text);

i can only see the class path我只能看到 class 路径

To correctly represent json returned by provided link you can use array of Class1 , not Rootobject :要正确表示提供的链接返回的 json ,您可以使用Class1数组,而不是Rootobject

var Data = Newtonsoft.Json.JsonConvert.DeserializeObject<Class1[]>(text);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法将当前 JSON object(例如 {“name”:“value”})反序列化为类型需要 JSON 数组(例如 [1,2,3] 才能正确反序列化) - Cannot deserialize the current JSON object (e.g. {“name”:“value”}) into type requires a JSON array (e.g. [1,2,3]) to deserialize correctly 无法将JSON数组(例如[1,2,3])反序列化为类型&#39;&#39;,因为类型需要JSON对象(例如{“ name”:“ value”}) - Cannot deserialize the JSON array (e.g. [1,2,3]) into type ' ' because type requires JSON object (e.g. {“name”:“value”}) 无法将当前JSON数组(例如[1,2,3])反序列化为类型”,因为该类型需要JSON对象(例如{“ name”:“ value”}) - Cannot deserialize the current JSON array (e.g. [1,2,3]) into type '' because the type requires a JSON object (e.g. {“name”:“value”}) 无法将 JSON 数组(例如 [1,2,3])反序列化为类型“ ”,因为类型需要 JSON 对象(例如 {&quot;name&quot;:&quot;value&quot;})才能正确反序列化 - Cannot deserialize the JSON array (e.g. [1,2,3]) into type ' ' because type requires JSON object (e.g. {"name":"value"}) to deserialize correctly 无法反序列化当前 JSON object 因为该类型需要 JSON 数组(例如 [1,2,3])才能正确反序列化 - Cannot deserialize the current JSON object because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly 无法将当前 JSON 对象(例如 {&quot;name&quot;:&quot;value&quot;})反序列化为类型 &#39;Value[]&#39;,因为该类型需要 JSON 数组(例如 [1,2,3]) - Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'Value[]' because the type requires a JSON array (e.g. [1,2,3]) 无法将当前 JSON objectT 反序列化为类型,因为该类型需要 JSON 数组(例如 [1,2,3])才能正确反序列化 - Cannot deserialize the current JSON objectT into type because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly 无法将当前JSON对象反序列化为类型&#39;WindowsService1 ...需要JSON数组(例如[1,2,3])才能正确反序列化 - Cannot deserialize the current JSON object into type 'WindowsService1…requires a JSON array (e.g. [1,2,3]) to deserialize correctly 无法将JSON对象(例如{“ name”:“ value”})反序列化为类型List`1 [JiraReporter.search]&#39;类型需要JSON数组才能正确反序列化 - Cannot deserialize JSON object (e.g. {“name”:“value”}) into type List`1[JiraReporter.search]' type requires a JSON array to deserialize correctly 如何修复“无法将当前的 JSON 数组反序列化为“段落”类型,因为需要 JSON object(例如 {“name”:“值”) - How to fix 'Cannot deserialize the current JSON array into type 'passages' because requires a JSON object (e.g. {“name”:“value”}) to deserialize
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM