Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将数据从JSON文件传输到列表项c#_C#_Json_List_Rest - Fatal编程技术网

将数据从JSON文件传输到列表项c#

将数据从JSON文件传输到列表项c#,c#,json,list,rest,C#,Json,List,Rest,我想把JSON数据放在一个列表中,向用户显示记录。但是当我运行系统时,列表只显示两次项目名称,而不显示JSON数据 HttpClient client = new HttpClient(); client.BaseAddress = new Uri("Http://www.eletrotechautomacoes.com.br"); string url = string.Format("/pontos/consulta.php"); var re

我想把JSON数据放在一个列表中,向用户显示记录。但是当我运行系统时,列表只显示两次项目名称,而不显示JSON数据

HttpClient client = new HttpClient();
        client.BaseAddress = new Uri("Http://www.eletrotechautomacoes.com.br");
        string url = string.Format("/pontos/consulta.php");
        var response = await client.GetAsync(url);
        var result = response.Content.ReadAsStringAsync().Result;
        List<ExchangeRates> listaProdutos = JsonConvert.DeserializeObject<List<ExchangeRates>>(result);

        this.LlistSpecials.ItemsSource = listaProdutos;
对象:

 public class ExchangeRates 
{

    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("nome")]
    public string Nome { get; set; }

    [JsonProperty("preco")]
    public string Preco { get; set; }

    [JsonProperty("tipo")]
    public string Tipo { get; set; }


}

谢谢大家的帮助。但即使是应用修正也不会继续。我认为问题在于:this.LlistSpecials.ItemsSource=listaProdutos;我的困难是显示列表中的内容。我需要对要显示的列表进行一些转换?他们知道显示此列表的程序吗?它当前两次返回项目名称。我认为这与JSON项的数量有关,JSON项也有两个。

更改您的
ExchangeRates
类,如下所示,因为
Id
将是一个
string
而不是
列表


更改您的
ExchangeRates
类,如下所示,因为
Id
将是
字符串
而不是
列表


如果你不知道你的模特应该看起来怎么样,你可以用这个

您的模型如下所示:

public class ExchangeRates
    {
        public string id { get; set; }
        public string nome { get; set; }
        public string preco { get; set; }
        public string tipo { get; set; }
    }

更新你的模型,它应该可以工作。

如果你不知道你的模型应该是什么样子,你可以用这个

您的模型如下所示:

public class ExchangeRates
    {
        public string id { get; set; }
        public string nome { get; set; }
        public string preco { get; set; }
        public string tipo { get; set; }
    }

更新你的模型,它应该可以工作。

@AnuradhS为什么会有帮助,如何帮助?HttpClient不是WebClient的继承者吗?它是新开发中使用的首选类吗?为什么您的属性
id
is
List
?由于您的json,它可能是
string
,然后可以淡化。如果您将
id
定义为
List
,那么json应该是
“id”:[“1”]
等等。@AnuradhS为什么会有帮助?HttpClient不是WebClient的继承者吗?它是新开发中使用的首选类吗?为什么您的属性
id
is
List
?由于您的json,它可能是
string
,然后可以淡化。如果您将
id
定义为
List
,那么json应该是
“id”:[“1”]
等。感谢您的帮助。但即使是应用修正也不会继续。我认为问题在于:this.LlistSpecials.ItemsSource=listaProdutos;我的困难是显示列表中的内容。我需要对要显示的列表进行一些转换?他们知道显示此列表的程序吗?它当前两次返回项目名称。我认为这与JSON项目的数量有关,这也是两个项目。谢谢大家的帮助。但即使是应用修正也不会继续。我认为问题在于:this.LlistSpecials.ItemsSource=listaProdutos;我的困难是显示列表中的内容。我需要对要显示的列表进行一些转换?他们知道显示此列表的程序吗?它当前两次返回项目名称。我认为这与JSON项的数量有关,这也是两个。
public class ExchangeRates
    {
        public string id { get; set; }
        public string nome { get; set; }
        public string preco { get; set; }
        public string tipo { get; set; }
    }