Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Convert Web API Json response to Entity Collection

Posted on by 475
HttpResponseMessage response = httpClient.GetAsync(ConfigurationManager.AppSettings["ServerAddress"] + "api/data/v8.0/" + uri, HttpCompletionOption.ResponseHeadersRead).Result;
            JObject responseObject = new JObject();
            if (response.IsSuccessStatusCode)
            {
                responseObject = JObject.Parse(response.Content.ReadAsStringAsync().Result);

 dynamic systemUserObject = JsonConvert.DeserializeObject(jRetrieveResponse.ToString());

                foreach (var data in systemUserObject.value)
                {
               var contactType= data.contacttype.Value;
                }
         
            }

Iam using Rest API to connect CRM and while converting Can we convert Json object to entity Collection ? or is there any easy way to convert response data to entity collection ? 

*This post is locked for comments

  • dkrishna Profile Picture
    dkrishna 475 on at
    RE: Convert Web API Json response to Entity Collection

    Here main problem is assining values to properties and need to check field existance before assining value to property like below ? Any Ideas?

      foreach (var data in systemUserObject.value)

                   {

                  var contactType= data.contacttype.Value;

                   }

  • dkrishna Profile Picture
    dkrishna 475 on at
    RE: Convert Web API Json response to Entity Collection

    here how can i check condition whether field present in json object before assigning value to property ? is there any other alternative which converts  response to entity collection when we use SOAP IOrganization Service ?

  • CRM Develope Profile Picture
    CRM Develope 884 on at
    RE: Convert Web API Json response to Entity Collection

    krishna prasad

    Have a look Here.

    https://yanivrdt.wordpress.com/2015/09/27/crm-web-api-preview-generate-strongly-typed-objects-from-metadata-document/

    if (retrieveResponse.IsSuccessStatusCode)

                   {

                       var Content = await retrieveResponse.Content.ReadAsStringAsync();

                       ODataResponse<T>  odataresponse = JsonConvert.DeserializeObject<ODataResponse<T>>(Content);

                   }

    public class ODataResponse<T>

    {

           public T[] Value { get; set; }

      }

    Kind regards,

    CRM Developer

  • Suggested answer
    Rawish Kumar Profile Picture
    Rawish Kumar 13,756 on at
    RE: Convert Web API Json response to Entity Collection

    Hi Krishna,

    It is Do-able : www.newtonsoft.com/.../ToObjectComplex.htm

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,000 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,658 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans