tags:

views:

103

answers:

3

Hi guys,

I know ODATA can return json but not sure if I have to use an attribute or interace to do so.

I want it to do just like http://odata.netflix.com/Catalog/Titles?$format=JSON but my odata service doesn't return JSON when i call it like www.foo.com/service?$format=json, it just returns XML.

What do I need to do to return json with ODATA?

thanks in advance

A: 

You need to add “Accept: application/json” into the request header section.

Check out this link

Glaxalg
that makes sense, I will try it out this week and let you guys knowthanks
wil
A: 

This turned out to be a pain in the a$$.

I just can't get this to work. I added "Accept: application/json" to the header.

[these guys didn't let me upload image]

but I get "The webpage cannot be found" using http://test.com/feed2/ODataService.svc/results?$format=JSON

and then even used contentType: "application/json but no go

called using $.ajax({ url: "http://test.com/feed2/ODataService.svc/results/", contentType: "application/json; charset=utf-8", dataType: "json", success: function(res) {
$("#test").text(res.d[0]); } });
and got permission error.

Any ideas guys?

wil
A: 

"...but I get "The webpage cannot be found" using http://test.com/feed2/ODataService.svc/results?$format=JSON ..."

you dont need the $format=JSON in the Uri.

Just use "http://test.com/feed2/ODataService.svc/results"

(with Accept: application/json in the request header)

skm