1

「long」という名前の json 要素にアクセスしようとしていますが、VS でエラーが発生し、16 ビットの符号付き整数として検出されます。要素 "long" と "short" を除いて、私がアクセスできる Json の他の要素。これを回避する方法はありますか?

var resultOpenPositions = JsonConvert.DeserializeObject<Root>(JsonopenPositions);
string ShrtLong = resultOpenPositions.positions[0].long.units; // long here gives error , vs detects it as a 16 bit signed integer

// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); 
    public class Long
    {
        public string averagePrice { get; set; }
        public string pl { get; set; }
        public string resettablePL { get; set; }
        public List<string> tradeIDs { get; set; }
        public string units { get; set; }
        public string unrealizedPL { get; set; }
    }

    public class Short
    {
        public string pl { get; set; }
        public string resettablePL { get; set; }
        public string units { get; set; }
        public string unrealizedPL { get; set; }
        public string averagePrice { get; set; }
        public List<string> tradeIDs { get; set; }
    }

    public class Position
    {
        public string instrument { get; set; }
        public Long @long { get; set; }
        public string pl { get; set; }
        public string resettablePL { get; set; }
        public Short @short { get; set; }
        public string unrealizedPL { get; set; }
    }

    public class Root
    {
        public string lastTransactionID { get; set; }
        public List<Position> positions { get; set; }
    }

これがjson部分です:

{
  "positions": [
    {
      "instrument": "EUR_USD",
      "long": {
        "units": "1",
        "averagePrice": "1.13093",
        "pl": "-1077.2255",
        "resettablePL": "-1077.2255",
        "financing": "-48.6223",
        "dividendAdjustment": "0.0000",
        "guaranteedExecutionFees": "0.0000",
        "tradeIDs": [
          "17800"
        ],
        "unrealizedPL": "-0.0001"
      },
      "short": {
        "units": "0",
        "pl": "-543.3196",
        "resettablePL": "-543.3196",
        "financing": "-3.1941",
        "dividendAdjustment": "0.0000",
        "guaranteedExecutionFees": "0.0000",
        "unrealizedPL": "0.0000"
      },
      "pl": "-1620.5451",
      "resettablePL": "-1620.5451",
      "financing": "-51.8164",
      "commission": "0.0000",
      "dividendAdjustment": "0.0000",
      "guaranteedExecutionFees": "0.0000",
      "unrealizedPL": "-0.0001",
      "marginUsed": "0.0333"
    }
  ],
  "lastTransactionID": "17800"
}
4

2 に答える 2