I am trying to parse a Json response in C#, but one of the parent nodes is a date like "2019-07-11." Normally I would just make classes to deserialize my response into, but this date node is throwing me for a loop.
Here is what I am doing. I am getting a JSON response and trying to deserialize it into nice classes:
rc.EndPoint = "https://api.nasa.gov/neo/rest/v1/feed?api_key=xxxxxxxxxxxx";
rc.Method = HttpVerb.GET;
response = rc.MakeRequest();
r = JsonConvert.DeserializeObject<RootAsteroidObject>(response);
Here are my classes:
public class RootAsteroidObject
{
public Links links { get; set; }
public int element_count { get; set; }
public NearEarthObjects near_earth_objects { get; set; }
}
public class NearEarthObjects
{
public string asteroid { get; set; }
}
public class AsteroidInfo
{
public string id { get; set; }
public string neo_reference_id { get; set; }
public string name { get; set; }
public string nasa_jpl_url { get; set; }
public double absolute_magnitude_h { get; set; }
}
In my RootAsteroidOjbect object after parsing it shows the element_count and links info just fine. However, the near_earth_objects is null. I realize this is because public class AsteroidInfo isn't in the response. The node has the name 2019-07-13. I don't know how to populate my AsteroidInfo class with this information.
Here is the first part of the JSON response I'm working with:
{
"links": {
"next": "http://www.neowsapp.com/rest/v1/feed?start_date=2019-07-18&end_date=2019-07-25&detailed=false&api_key=xxxxxxxxxxxxxxxxxxxxxxx",
"prev": "http://www.neowsapp.com/rest/v1/feed?start_date=2019-07-04&end_date=2019-07-11&detailed=false&api_key=xxxxxxxxxxxxxxxxxxxxxxxx",
"self": "http://www.neowsapp.com/rest/v1/feed?start_date=2019-07-11&end_date=2019-07-18&detailed=false&api_key=xxxxxxxxxxxxxxxxxxxxxxxx"
},
"element_count": 70,
"near_earth_objects": {
"2019-07-13": [
{
"links": {
"self": "http://www.neowsapp.com/rest/v1/neo/3842954?api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
"id": "3842954",
"neo_reference_id": "3842954",
"name": "(2019 MW1)",
"nasa_jpl_url": "http://ssd.jpl.nasa.gov/sbdb.cgi?sstr=3842954",
"absolute_magnitude_h": 24.505,
"estimated_diameter": {
"kilometers": {
"estimated_diameter_min": 0.0333852764,
"estimated_diameter_max": 0.0746517476
},
I would like to know an approach to get the info under the 2019-07-13 node.
Thanks