这是我获取到 TeamCitySharp 服务器的 Json 连接的代码。本地主机是我的 Json 连接。现在,我试图在我转到本地主机时显示开始日期,但它显示为空。有想法该怎么解决这个吗?
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost:81/Status/AllStatuses");
var response = request.GetResponse();
var reader = new StreamReader(response.GetResponseStream());
var responseString = reader.ReadToEnd();
var serializer = new JavaScriptSerializer();
serializer.RegisterConverters((new[] { new DynamicJsonConverter() }));
dynamic obj = serializer.Deserialize(responseString, typeof(object));
foreach (var objects in obj)
{
foreach (var project in client.Projects)
{
foreach (var build in project.Builds)
{
bs.date = project.ProjectStartDate.ToString();
这是在单独项目中的另一个控制器上调用 Jsonresult。
public JsonResult AllStatuses() //from the json called in the _client view
{
var buildStatuses = new List<BuildStatus>();
var projects = Client.AllProjects();
//var projects = storeDB.Projects.Include("Builds").ToList();
//var buildStatuses = new List<BuildStatus>();
foreach (var project in projects)
{
try
{
var buildConfigs = Client.BuildConfigsByProjectId(project.Id);
foreach (var buildConfig in buildConfigs)
{
var build = Client.LastBuildByBuildConfigId(buildConfig.Id);
var b = new BuildStatus();
b.id = buildConfig.Id.ToString();
if (b.date != null)
b.date = b.date.ToString();
if (b.status != null)
b.status = build.Status.ToString();
buildStatuses.Add(b);
}
} catch { }
}
//var query = buildStatuses.OrderBy(x => x.status); // Create a sorted list from Error - Unknown
return Json(buildStatuses, JsonRequestBehavior.AllowGet);
}