簡體   English   中英

JSON 反序列化 c# 從 class 獲取值

[英]JSON deserialize c# get values from class

我正在嘗試反序列化文件。

我的文件 plik.json 看起來像: https://api.jsonstorage.net/v1/json/2fc690dd-fe2e-40cc-b7ce-a34b8326ed33

這是我的代碼:

 public class Filter
    {
        public string filterType { get; set; }
        public string minPrice { get; set; }
        public string maxPrice { get; set; }
        public string tickSize { get; set; }
        public string multiplierUp { get; set; }
        public string multiplierDown { get; set; }
        public int? avgPriceMins { get; set; }
        public string minQty { get; set; }
        public string maxQty { get; set; }
        public string stepSize { get; set; }
        public string minNotional { get; set; }
        public bool? applyToMarket { get; set; }
        public int? limit { get; set; }
        public int? maxNumOrders { get; set; }
        public int? maxNumAlgoOrders { get; set; }
    }

    public class Symbol
    {
        public string symbol { get; set; }
        public string status { get; set; }
        public string baseAsset { get; set; }
        public int baseAssetPrecision { get; set; }
        public string quoteAsset { get; set; }
        public int quotePrecision { get; set; }
        public int quoteAssetPrecision { get; set; }
        public int baseCommissionPrecision { get; set; }
        public int quoteCommissionPrecision { get; set; }
        public List<string> orderTypes { get; set; }
        public bool icebergAllowed { get; set; }
        public bool ocoAllowed { get; set; }
        public bool quoteOrderQtyMarketAllowed { get; set; }
        public bool isSpotTradingAllowed { get; set; }
        public bool isMarginTradingAllowed { get; set; }
        public List<Filter> filters { get; set; }
        public List<string> permissions { get; set; }
    }

    public class Root
    {
        public List<Symbol> symbols { get; set; }
    }

    private void button29_Click(object sender, EventArgs e)
    {

        using (StreamReader r = new StreamReader("C:\\Users\\Adamsz\\Pictures\\plik.json"))
        {
            Console.WriteLine("Before");
            string json = r.ReadToEnd();
           // Console.WriteLine(json);
            Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(json);
            Console.WriteLine("After");

        }

        
           List<Symbol> xd = new List<Symbol>();
        foreach (var m in xd)
        {
            Console.WriteLine(m.symbol.ToString());
            List <Filter> filtr = new List<Filter>();
            foreach (var x in filtr)
            {
                if (x.filterType == "LOT_SIZE")
                {
                    Console.WriteLine(x.minQty);
                }
                   
            }
        }
       

    }

現在我遇到了 WrtieLine 的問題。 我應該在我的代碼中進行哪些更改才能准確地得到這個 output? 提前致謝: OutPut 應該是這樣的:

ETHBTC

0.00100000

LTCBTC

0.01000000

 List<Symbol> symbols = myDeserializedClass.symbols;
            foreach (var m in symbols)
            {

                Console.WriteLine(m.symbol.ToString());
                List<Filter> filtr = m.filters;
                foreach (var x in filtr)
                {
                    if(x.filterType == "LOT_SIZE")
                    Console.WriteLine(x.minQty);
                }
            }

這就是我一直在尋找的...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM