web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Convert Web API Json response to Entity Collection

(0) ShareShare
ReportReport
Posted on by 483
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

I have the same question (0)
  • dkrishna Profile Picture
    483 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
    483 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
    894 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
    13,758 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans