Marco Fleig

Marco Fleig

  • NA
  • 47
  • 670

JSON - DeserializeObject

Jan 24 2020 12:29 AM

Hi

Is there someone how knows/sees what I am doing wrong ...

I seem to be missing the point here:

I have a json string (got by webService):

  1. var mRestClient = new RestClient();   
  2. mRestClient.AddDefaultHeader("Authorization""Bearer " + );  
  3. var getRequest = new RestRequest(Method.GET);  
  4. System.Net.HttpStatusCode returnStatus = mRestClient.Get(getRequest).StatusCode;  
  5. string json = mRestClient.Get(getRequest).Content;
then my string json contains:
  1. {  
  2. "items" : [ {  
  3. "id" : "459cb42f-2190-4cd3-a0c4-610130611316",  
  4. "name" : "you name it ...",  
  5. "externalId" : "c2002c7a-32bd-4d04-ba0c-c0633e4bc7a5",  
  6. "start" : "2020-01-01",  
  7. "finish" : "2020-06-01",  
  8. "manager" : {  
  9. "id" : "1cce4511-2c6a-4070-b1bc-7a863b4f34bb"  
  10. }, {…}  
  11. ]  
  12. }  

I just want to get id and name with this code:

and I have the declare ...

  1. public class TestProjectList  
  2. {  
  3.     public TestProject[] TestProject { get; set; }  
  4. }  

  5. public class TestProject   
  6. {  
  7.     public string _id { get; set; }
  8.     public string _name { get; set; }
  9. }  

After execute this line …

  1. TestProject testProjectList = JsonConvert.DeserializeObject(json);  

testProjectList contains:

  1. _id: null  
  2. _name: null  
Thanks for every hint. 

Answers (3)