C# Google API-向属性添加API值
我正在使用谷歌api,我需要一些转换,以便能够获得我想要的值 向Google api发送查询请求时,它会返回字符串列表,如下所示:C# Google API-向属性添加API值,c#,list,properties,indexing,google-api,C#,List,Properties,Indexing,Google Api,我正在使用谷歌api,我需要一些转换,以便能够获得我想要的值 向Google api发送查询请求时,它会返回字符串列表,如下所示: //Request to Google API Google.Apis.Analytics.v3.Data.GaData d = r.Execute(); //The property in Gadata used to query Google data public virtual IList<IList<string>&g
//Request to Google API
Google.Apis.Analytics.v3.Data.GaData d = r.Execute();
//The property in Gadata used to query Google data
public virtual IList<IList<string>> Rows { get; set; }
主要内容:
static void Main(字符串[]args)
{
列表日期=新列表();
GAStatistics Date1=新GAStatistics(){Dates=“20140228”,Visitors=“871”};
GAStatistics Date2=新的GAStatistics(){Dates=“20140227”,Visitors=“593”};
GAStatistics Date3=新GAStatistics(){Dates=“20140226”,Visitors=“553”};
添加(日期1);
添加(日期2);
列表日期。添加(日期3);
var Exp=string.Join(Environment.NewLine,ListDates.Select(e=>string.Format(“{0}”),e.Dates++'+'-“++'+e.Visitors)).ToArray();
控制台写入线(Exp);
Console.ReadLine();
}
}
这里我有两个属性可以用于其他Google API:
问题是:我是否可以创建一个包含日期和访问者属性的类,并将它们声明为行中的值
谢谢大家!
/克里斯问题解决了
类别:
public class GAStatistics
{
public string Date { get; set; }
public string Visitors { get; set; }
public GAStatistics(string _date, string _visitors)
{
Date = _date;
Visitors = _visitors;
}
}
主程序:
public class GAStatistics
{
public string Date { get; set; }
public string Visitors { get; set; }
public GAStatistics(string _date, string _visitors)
{
Date = _date;
Visitors = _visitors;
}
}
通过使用Google Analytics API中每行的数据填充ListGaVisitors来增加GaVisitions
List<GAStatistics> ListGaVisitors = new List<GAStatistics>();
foreach (var row in d.Rows)
{
GAStatistics GaVisits = new GAStatistics(row[0], row[1]); // This!
ListGaVisitors.Add(GaVisits);
}
List ListGaVisitors=new List();
foreach(变量行在d.Rows中)
{
GAStatistics=newgastatistics(行[0],行[1]);//这个!
listgagvisitors.Add(gavisitors);
}
结果:
public class GAStatistics
{
public string Date { get; set; }
public string Visitors { get; set; }
public GAStatistics(string _date, string _visitors)
{
Date = _date;
Visitors = _visitors;
}
}
List<GAStatistics> ListGaVisitors = new List<GAStatistics>();
foreach (var row in d.Rows)
{
GAStatistics GaVisits = new GAStatistics(row[0], row[1]); // This!
ListGaVisitors.Add(GaVisits);
}