【问题标题】:Display json array data through List in Asp.netAsp.net中通过List显示json数组数据
【发布时间】:2012-11-03 06:42:58
【问题描述】:

我的 C# 类

public class City
{

   public int City_id { get; set; }

    public string City_name { get; set; }
}

public class Model
{
    public City[] lstCitiesResult { get; set; }
}

我的代码:

namespace gtp2
{
  ....
  List<Model> li = new List<Model>();

  WebClient re = new WebClient();

  var data = re.DownloadString("url");

  var a = JsonConvert.DeserializeObject<Model>(data);


  Response.Write(a.lstCitiesResult.ToString());
  ....
}

Response.Write 我得到了这样的结果:gtp2.City[] Any Ideya?提前谢谢

【问题讨论】:

    标签: asp.net json web-services


    【解决方案1】:

    看起来结果是City 的数组,因此您需要循环遍历它。但是您可以使用处理集合的控件来显示它,例如ListView、DataList 等。试试这个:

    string output = "";
    foreach(var c in a.lstCitiesResult)
    {
       output = output + String.Format("id: {0}, name: {1}", c.City_id, c.City_name);
    }
    
    Response.Write(output);
    

    【讨论】:

      猜你喜欢
      • 2020-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      • 2017-08-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多