In theory you should only read the content of the json, save it in string
and pass that variable for its deserialization .
string jsonPath = System.IO.File.ReadAllText(json);
var jsonD = JsonConvert.DeserializeObject<ClimaHour>(jsonPath);
The only strange thing I noticed in your question was that you were trying to deserialize a list ( List<ClimaHour>
) of ClimaHour
when it should only be Objeto
.
Another thing is that you use Json.deserialize ... I searched for that library and I did not find it = /, so the answer I gave is using Newtonsoft .
Now, as you indicate a url
for said JSON and this one is in Google Drive , we must build a function that returns a valid url for the deserialization of the json .
Helpers helper = new Helpers();
using (var web = new WebClient())
{
string data = string.Empty;
string url = helper.GetGoogleDriveDownloadLinkFromUrl("https://drive.google.com/file/d/1A9-6o99kcIqRM3CEaXxYwh_Dv-vUkvnM/view");
data = web.DownloadString(url);
var json = JsonConvert.DeserializeObject<ClimaHour>(data);
}
And the implementation of the method GetGoogleDriveDownloadLinkFromUrl
, which is inside the class Helpers
public class Helpers
{
public string GetGoogleDriveDownloadLinkFromUrl(string url)
{
int index = url.IndexOf("id=");
int closingIndex;
if (index > 0)
{
index += 3;
closingIndex = url.IndexOf('&', index);
if (closingIndex < 0)
closingIndex = url.Length;
}
else
{
index = url.IndexOf("file/d/");
if (index < 0)
return string.Empty;
index += 7;
closingIndex = url.IndexOf('/', index);
if (closingIndex < 0)
{
closingIndex = url.IndexOf('?', index);
if (closingIndex < 0)
closingIndex = url.Length;
}
}
return $"https://drive.google.com/uc?id={url.Substring(index, closingIndex - index)}";
}
}
I can not take all the credit and I mention that the function that the url creates extracted it from this link ; the way to call this function can be creating a class (as I did) or within the same class that reads the JSON
, that I leave at your discretion colleague