0

I keep getting an error after running the code for a few minutes

Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[BitMEX.Order]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3])

Can you please help me?

public List<Position> GetOpenPositions(string symbol)
{
    var param = new Dictionary<string, string>();

    string res = Query("GET", "/position", param, true);

    return JsonConvert.DeserializeObject<List<Position>>(res)
        .Where(a => a.Symbol == symbol && a.IsOpen == true)
        .OrderByDescending(a => a.TimeStamp)
        .ToList();
}
6
  • You are getting this error because you are getting back an Object rather than an array, to check it try this JsonConvert.DeserializeObject<Position>(res).Where(a => a.Symbol == symbol && a.IsOpen == true).OrderByDescending(a => a.TimeStamp) Commented Jan 16, 2018 at 3:15
  • why you are doing .ToList() to your result? try removing it Commented Jan 16, 2018 at 3:19
  • @progrAmmar I suggest you to make your comment an answer, because it looks correct, and no one will answer it anymore. But this question will be marked as unanswered. Commented Jan 16, 2018 at 4:05
  • I tried removing .ToList() and it returns another error. Commented Jan 16, 2018 at 4:18
  • return JsonConvert.DeserializeObject<Position>(res) .Where(a => a.Symbol == symbol && a.IsOpen == true) .OrderByDescending(a => a.TimeStamp); Can you try this? Commented Jan 16, 2018 at 4:31

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.