C#-从序列化的字符中提取数据

时间:2018-07-06 15:07:08

标签: c# arrays json

我对此有些疑惑。我正在获取一个对象并对其进行序列化,它最终看起来像某种json,但事实并非如此。 foreach(测试仪中的var t)最终会打印每个字符。

var info = await client.GetAccountInformation();

            var tester = JsonConvert.SerializeObject(info);
            Console.WriteLine(tester);
          foreach (var t in tester)
            {
                Console.WriteLine(t);
               //t is a char
            }

实际数据如下:

{  
   "MakerCommission":10,
   "TakerCommission":10,
   "BuyerCommission":0,
   "SellerCommission":0,
   "CanTrade":true,
   "CanWithdraw":true,
   "CanDeposit":true,
   "Balances":[  
      {  
         "Asset":"BTC",
         "Free":0.00000372,
         "Locked":0.00000000
      },
      {  
         "Asset":"LTC",
         "Free":0.00000000,
         "Locked":0.00000000
      },

有没有什么方法可以获取此{“ Asset”:“ BTC”,“ Free”:0.00000372,“ Locked”:0.00000000}而无需遍历所有字符并比较字符串?

1 个答案:

答案 0 :(得分:1)

只需执行以下操作:

var info = await client.GetAccountInformation();

foreach (var balance in info.Balances)
{
     var serializedBalanceObject = JsonConvert.SerializeObject(balance);
     Console.WriteLine(serializedBalanceObject.ToString());
}