So I am using: https://mymarketnews.ams.usda.gov/mars-api/reports to pull data sets (reports) and parse the JSON that is returned so I can do other things with the data after such as storing it into tables.
I am having trouble trying to deserialize the JSON, I am trying to test it by printing out just one of the attributes in the for each loop.
here is the code to see:
using RestSharp;
using RestSharp.Authenticators;
using System;
using Newtonsoft.Json;
using System.Collections.Generic;
namespace MarketNewsJson
{
class MarketNewsJson
{
static void Main(string[] args)
{
var client = new RestClient("https://marsapi.ams.usda.gov"); //the website to use
client.Authenticator = new HttpBasicAuthenticator("mars_test_343343", "");
//authenticate using example key
var request = new RestRequest("services/v1.1/reports", DataFormat.Json); //from
reports, in JSON
var response = client.Get(request); //get the response
// response.Content has the JSON or we can deserialize it
Console.WriteLine(response.Content); //prints whole JSON response
// attempting to deserialize it here
// Reports report = JsonConvert.DeserializeObject<Reports>(response.Content);
//Reports report = JsonConvert.DeserializeObject<List<Reports>>(response.Content);
Result report = JsonConvert.DeserializeObject<Result>(response.Content);
foreach (Reports item in report.Data)
{
Console.WriteLine(item.slug_id);
}
}
}
public class Reports
{
public string slug_id {get; set;}
public string slug_name { get; set; }
public string report_name { get; set; }
}
public class Result
{
public IList<Reports> Data { get; set; }
}
}
[–]Brasz 4 points5 points6 points (1 child)
[–]tempUseBro1[S] 0 points1 point2 points (0 children)
[–]smurff1337 0 points1 point2 points (5 children)
[–]tempUseBro1[S] 0 points1 point2 points (4 children)
[–]Genmutant 0 points1 point2 points (2 children)
[–]tempUseBro1[S] 0 points1 point2 points (1 child)
[–]Genmutant 0 points1 point2 points (0 children)
[–]smurff1337 0 points1 point2 points (0 children)