I am calling an API that is quite long, and despite my best efforts, I have been unable to get the examples to work and I am not entirely sure where to go from here.
I have no issue obtaining the json as a string. When I did json to classes, I get the below (though it is even longer).
Now my issue is I want to get the Name and ID from Item.
But after spending a couple of hours in google, stack overflow and even NewtonSoft's documentation, I can't get it to work.
I tried JObject, JToken neither seem to be able to retrieve a 3rd? level item from the Json - I say 3rd, because it appears that the Item class is within the Request class, which is itself within the Rootobject class. When I tried JObject/JToken (can't remember which now I have used both for hours) - I got an error that it was returning :{ - which means that it was not finding the underlying name but rather just the two characters after item in:
Any pointers would be gratefully received because my brain is beginning to hurt.
Edited to add the json example in its original form:
I have no issue obtaining the json as a string. When I did json to classes, I get the below (though it is even longer).
C#:
public class ItemModel
{
public class Rootobject
{
public Request request { get; set; }
public Response_Status response_status { get; set; }
}
public class Request
{
public object testOne { get; set; }
public string testTwo { get; set; }
public Resolution resolution { get; set; }
public Item item { get; set; }
}
public class Resolution
{
public object[] resolution_attachments { get; set; }
}
public class Item
{
public string name { get; set; }
public string id { get; set; }
}
}
Now my issue is I want to get the Name and ID from Item.
But after spending a couple of hours in google, stack overflow and even NewtonSoft's documentation, I can't get it to work.
I tried JObject, JToken neither seem to be able to retrieve a 3rd? level item from the Json - I say 3rd, because it appears that the Item class is within the Request class, which is itself within the Rootobject class. When I tried JObject/JToken (can't remember which now I have used both for hours) - I got an error that it was returning :{ - which means that it was not finding the underlying name but rather just the two characters after item in:
JSON:
"item":{ "name": "Bob", "id": "1"},
Any pointers would be gratefully received because my brain is beginning to hurt.
Edited to add the json example in its original form:
JSON:
{
"request":
{
"test1": null
"test2": "one"
"test3":
{
"test4": 1
"test5": 3
},
"Test6": null,
"Test7":
{
"name": "Ted",
"id": "tedID"
},
"item":
{
"name": "itemName"
"id": "itemID"
},
}
}
Last edited: