我花了几个小时在这上面,仍然找不到答案。我有一个需要反序列化的 Json 字符串。它应该很简单,但我收到以下错误消息:
解析值时遇到意外字符:Q. Path '', line 0, position 0。
我的 json 字符串如下:
它是 Quandl 在线数据库提供的 Json 字符串的链接。
我使用了以下网站:
生成必要的类。
我知道我必须使用以下方法反序列化到这个类:
var result = JsonConvert.DeserializeObject<List<RootObject>>(request.jsonString);
但它不工作。
这是我的完整代码:
public class Errors
{
}
public class RootObject
{
public Errors errors { get; set; }
public int id { get; set; }
public string source_name { get; set; }
public string source_code { get; set; }
public string code { get; set; }
public string name { get; set; }
public string urlize_name { get; set; }
public string display_url { get; set; }
public string description { get; set; }
public string updated_at { get; set; }
public string frequency { get; set; }
public string from_date { get; set; }
public string to_date { get; set; }
public List<string> column_names { get; set; }
public bool @private { get; set; }
public object type { get; set; }
public bool premium { get; set; }
public List<List<object>> data { get; set; }
}
private void PullFromQuandl()
{
QuandlDownloadRequest request = new QuandlDownloadRequest();
request.APIKey = "Mi1xP1q2776TU4kmGcHo";
request.Datacode = new Datacode("FRED", "GDP");
request.Format = FileFormats.JSON;
request.Frequency = Frequencies.Monthly;
request.Truncation = 100;
request.Sort = SortOrders.Ascending;
string jsonString = request.ToRequestString();
var result = JsonConvert.DeserializeObject<List<RootObject>> (jsonString);
}