2

我的 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?提前谢谢

4

1 回答 1

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);
于 2012-11-03T06:53:27.530 回答