Hi
I am trying to deserialize this json returned from this url -https://api.coindesk.com/v1/bpi/currentprice.json
However, I am getting the above error.
This is my code :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Jsonapi
{
class Program
{
static void Main(string[] args)
{
HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create(string.Format("https://api.coindesk.com/v1/bpi/currentprice.json"));
WebReq.Method = "GET";
HttpWebResponse WebResp = (HttpWebResponse)WebReq.GetResponse();
Console.WriteLine(WebResp.StatusCode);
Console.WriteLine(WebResp.Server);
string jsonString;
using (Stream stream = WebResp.GetResponseStream()) //modified from your code since the using statement disposes the stream automatically when done
{
StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8);
jsonString = reader.ReadToEnd();
}
List<Root> friends = JsonConvert.DeserializeObject<List<Root>>(jsonString);
}
}
}
I am not sure how to read the json strings into the list format, could someone please guide me. I have generated the class for the json though.
{
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
public class Time
{
public string updated { get; set; }
public DateTime updatedISO { get; set; }
public string updateduk { get; set; }
}
public class USD
{
public string code { get; set; }
public string symbol { get; set; }
public string rate { get; set; }
public string description { get; set; }
public double rate_float { get; set; }
}
public class GBP
{
public string code { get; set; }
public string symbol { get; set; }
public string rate { get; set; }
public string description { get; set; }
public double rate_float { get; set; }
}
public class EUR
{
public string code { get; set; }
public string symbol { get; set; }
public string rate { get; set; }
public string description { get; set; }
public double rate_float { get; set; }
}
public class Bpi
{
public USD USD { get; set; }
public GBP GBP { get; set; }
public EUR EUR { get; set; }
}`