遇到意外的字符(我在哪里可以找到意外的字符?)

时间:2018-02-05 20:21:17

标签: c#

我一直收到这个错误...

Newtonsoft.Json.JsonReaderException
Unexpected character encountered while parsing value:<. Path '', line 0, 
position 0- 

我的问题是我能找到意想不到的角色?或者我如何修复我的代码? GetOpenPositions和GetOpenOrders返回Json.Convert时发生错误。谢谢!

namespace BitMEX
{
public class OrderBookItem
{
public string Symbol { get; set; }
public int Level { get; set; }
public int BidSize { get; set; }
public decimal BidPrice { get; set; }
public int AskSize { get; set; }
public decimal AskPrice { get; set; }
public DateTime Timestamp { get; set; }
}

public List<Position> GetOpenPositions(string symbol)
{
    var param = new Dictionary<string, string>();
    string res = Query("GET", "/position", param, true);
    return (dynamic)JsonConvert.DeserializeObject<List<Position>>
(res).Where(a => a.Symbol == symbol && a.IsOpen == true).OrderByDescending(a 
=> a.TimeStamp).ToList();

}

public List<Order> GetOpenOrders(string symbol)
{
    var param = new Dictionary<string, string>();
    param["symbol"] = symbol;
    param["reverse"] = true.ToString();
    string res = Query("GET", "/order", param, true);
    return JsonConvert.DeserializeObject<List<Order>>(res).Where(a => 
 a.OrdStatus == "New" || a.OrdStatus 
 =="PartiallyFilled").OrderByDescending(a => a.TimeStamp).ToList();

}

1 个答案:

答案 0 :(得分:1)

由于<,它似乎正在尝试解析XML。 Json字符串应以{[

开头
    Newtonsoft.Json.JsonReaderException
    Unexpected character encountered while parsing value:<. Path '', line 0, 
    position 0-