Search code examples
jsonweb-servicesodatamicrosoft-dynamics

Querying Microsoft Dynamics NAV 2013 Odata service as JSON Format


i have read here, that the Odata Webservice also supports the JSON format. But how can I get that?

When I send a request i only get the following format> application/atom+xml


Solution

  • Try something like that:

    $.ajax({
           type: "GET",
           contentType: "application/json; charset=utf-8",
           datatype: "json",
           url: odataSelect,
           beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
           success: function (data, textStatus, XmlHttpRequest) 
               { 
                   ProcessReturnedEntities(data.d.results); 
                   ProcessReturnedEntity(data.d);
               },
           error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
       });
    

    See this site for a complete example.