通过Asp.net中的List显示json数组数据

时间:2012-11-03 06:42:59

标签: asp.net json web-services

我的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 []任何Ideya?提前感谢

1 个答案:

答案 0 :(得分:0)

看起来结果是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);