I have spent a few hours on this and still can't find the answer. I have a Json string I need to deserialize. It should be simple but I get the following error message:
Unexpected character encountered while parsing value: Q. Path '', line 0, position 0.
My json string is the following:
It is a link to a Json string provided by the Quandl online database.
I used the following website:
to generate the necessary class.
I understand I then to have to deserialize into this class using:
var result = JsonConvert.DeserializeObject<List<RootObject>>(request.jsonString);
but it is not working.
Here is my full code:
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);
}
You could mark this as an answer, because what you posted as an answer could be done much more easily from a look at the quandl api:
using QuandlCS.Connection; // need to use this
and then
QuandlConnection conn = new QuandlConnection ();
string json = conn.Request(request); // request is your QuandlDownloadRequst
RootObject obj = JsonConvert.DeserializeObject<RootObject>(json);
that is the same as in you answer. they have a class for that :D
for further reference look at their C# api docs: https://github.com/HubertJ/QuandlCS