我如何在C#中保存到scv? [英] How can I in C# save to scv?

查看:92
本文介绍了我如何在C#中保存到scv?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试写方法,允许我将我的信息(从API)保存到csv。



这是一段代码:

 static void Main(string [] args)
{
if(args == null)
{
抛出新的ArgumentNullException(nameof(args));
}
QuickIAWebRequest webR =新的QuickIAWebRequest(MSFT,TIME_SERIES_DAILY);
string data = webR.Download();
/ ***************************** /
tickerData tickerData = JsonConvert.DeserializeObject< tickerData>(数据);

foreach(var i in tickerData.TimeSeriesData.Values)
{
Console.WriteLine(string.Concat(i.Close,,i.Open));
}
Console.ReadLine();


/ ************************************* * /

公共类tickerData
{
内部静态IEnumerable< object>时间序列;

public tickerData()
{}

[JsonProperty(PropertyName =Meta Data)]
public Meta_data Metadata {get;组; }

[JsonProperty(PropertyName =时间序列(每日))]
public Dictionary< string,TimeSeries> TimeSeriesData {get;组; }
}





我尝试过:



我试过了一些编写器,但是这是错的。

解决方案

你可以用很多方法来编写一个CSV文件。您可以考虑使用此示例<而不是滚动您自己的实现。 / a> [ ^ ]。

I try write method wich allow me save my information (from API) to csv.

Here's piece of code:

 static void Main(string[] args)
        {  
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }
            QuickIAWebRequest webR = new QuickIAWebRequest("MSFT", "TIME_SERIES_DAILY");
            string data = webR.Download();
            /*****************************/
            tickerData tickerData = JsonConvert.DeserializeObject<tickerData>(data);

                foreach (var i in tickerData.TimeSeriesData.Values)
                { 
                    Console.WriteLine(string.Concat(i.Close, "  ", i.Open));
                }    
                Console.ReadLine();


/**************************************/

 public class tickerData
    {
        internal static IEnumerable<object> timeseries;

        public tickerData()
        { }

        [JsonProperty(PropertyName = "Meta Data")]
        public Meta_data Metadata { get; set; }

        [JsonProperty(PropertyName = "Time Series (Daily)")]
        public Dictionary<string, TimeSeries> TimeSeriesData { get; set; }
    }



What I have tried:

I tried streamwriter but something It's wrong.

解决方案

There are many approaches that you can take to write a CSV file. Rather than rolling your own implementation, you could consider using something like this example[^].


这篇关于我如何在C#中保存到scv?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆