问题描述
我是C#和.Net平台的新手(从Javascript世界过来),所以任何帮助/样本都会很棒。
I'm very new to C# and the .Net platform(crossing over from Javascript world), so any help/samples would be great.
高级开发人员编写了一个程序,该程序目前使用API中的数据并转换为JSON格式。我现在需要编写一个方法来获取这些数据并在收集数据后创建一个CSV(;)分隔文件。
A senior developer has written a program, that currently consumes data from an API and converts to a JSON format. I now need to write a method that will take this data and create a CSV (;) delimited file after the data is gathered.
任何关于如何实现这一点的想法,或者这是否可能?
Any thoughts on how to accomplish this, or is this even possible?
public class ConvertToCsv
{
private GetUserData GetUserFromRest(SessionData sessionData, string userId)
{
var restProxy = new CsodRestProxy();
GetUserData getUserData = null;
var v = restProxy.GetUser(sessionData.Token, sessionData.Secret, ENV.EnvironmentName, null, userId);
try
{
getUserData = JsonConvert.DeserializeObject<ENV.GetUserData>(v);
}
catch (Exception) { }
return getUserData;
}
}
还有RestProxy.cs实际通过API进行身份验证并返回数据。这是代码。这是我应该构建CreateCSV方法吗?
There is also the RestProxy.cs that actually authenticates with the API and returns the data. Here's the code. Is this were I should build the CreateCSV method?
string responseFromServer = "";
try
{
using (StreamReader reader = new StreamReader(request.GetResponse().GetResponseStream()))
{
responseFromServer = reader.ReadToEnd();
}
}
catch(WebException we)
{
var reader = new StreamReader(we.Response.GetResponseStream());
responseFromServer = reader.ReadToEnd();
}
catch (Exception e) {
responseFromServer = (e.Message + " \n" + e.StackTrace);
}
return responseFromServer;
}
感谢任何帮助!
Thankful for any help!
推荐答案
这篇关于从API获取数据创建CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!