我有一个从 Fitbit 获取数据的示例项目,但信息采用公制而不是英制。这是使用 TimeSeriesDataList 类提取日期和字符串对列表的代码,但以公里而不是英里为单位。如何修改此代码以获取英里而不是公里的数据?任何帮助是极大的赞赏。
public class TimeSeriesDataList
{
public List<Data> DataList { get; set; }
public class Data
{
public DateTime DateTime { get; set; }
public string Value { get; set; }
}
}
public class FitbitClient : IFitbitClient
{
/// <summary>
/// Get TimeSeries data for another user accessible with this user's credentials
/// </summary>
/// <param name="timeSeriesResourceType"></param>
/// <param name="startDate"></param>
/// <param name="endDate"></param>
/// <param name="userId"></param>
/// <returns></returns>
private TimeSeriesDataList GetTimeSeries(TimeSeriesResourceType timeSeriesResourceType, DateTime baseDate, string endDateOrPeriod, string userId)
{
string userSignifier = "-"; //used for current user
if (!string.IsNullOrWhiteSpace(userId))
userSignifier = userId;
// Here is where I believe I need to make a change, somehow, so that
// data that comes in when this is string is requested, comes in metric units
string requestUrl = string.Format("/1/user/{0}{1}/date/{2}/{3}.xml", userSignifier, StringEnum.GetStringValue(timeSeriesResourceType), baseDate.ToString("yyyy-MM-dd"), endDateOrPeriod);
RestRequest request = new RestRequest(requestUrl);
request.OnBeforeDeserialization = resp => {
XDocument doc = XDocument.Parse(resp.Content);
//IEnumerable<XElement> links = doc.Descendants("result");
var rootElement = doc.Descendants("result").FirstOrDefault().Descendants().FirstOrDefault();
if (rootElement != null && !string.IsNullOrWhiteSpace(rootElement.Name.LocalName))
request.RootElement = rootElement.Name.LocalName;
};
var response = restClient.Execute<TimeSeriesDataList>(request);
HandleResponse(response);
return response.Data;
}
}
编辑我希望通过在标题中添加一些类似于“Accept-Language”的内容来获取已经转换的数据,但我不知道如何利用这个概念。我想到了使用转换,但此时我想看看是否有一种更简单的方法,即添加一个简单的标题,而不是为每个场景、保存数据的类、每个不同的区域等创建一个转换类。