The JSON format follows the data encoding described in the RFC 4627 to represent data using a subset of the JavaScript syntax. For more information on JSON see RFC 4627 in the IETF web site (http://tools.ietf.org/html/rfc4627) and the http://json.org web site.
Here is the request which should be sent to the Data Service enabled application to enforce JSON rendering instead of default one, which is ATOM:
GET /DataServiceWebApp/BestFlightService.svc/TFlights2 HTTP/1.1
Accept-Language: en-GB,de;q=0.8,de-DE;q=0.5,de-LU;q=0.3
UA-CPU: x86
Accept: application/json
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; .NET CLR 3.5.21022; InfoPath.2; MS-RTC LM 8)
Host: dado-nb0
Proxy-Connection: Keep-Alive
Notice the red marked line above. Note that default request instead of application/json looks like:
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-silverlight, */*
And, here is the JSON formatted response:
HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Type: application/json
Server: Microsoft-IIS/7.0
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
Date: Tue, 15 Apr 2008 11:37:28 GMT
Content-Length: 4082
{ "d" : [
{
__metadata: {
uri: "http://dado-nb0/DataServiceWebApp/BestFlightService.svc/TFlights2(1)", type: "BestFlightDemoDbModel.TFlights2"
}, ID: "1", Airline: "Lufthansa", Price: "1200", StartLocation: "Frankfurt", Destination: "Hamburg", DepartureTime: "\/Date(1208275200000)\/", ArrivalTime: "\/Date(1208271600000)\/", Provider: "P02"
}, {
__metadata: {
uri: "http://dado-nb0/DataServiceWebApp/BestFlightService.svc/TFlights2(2)", type: "BestFlightDemoDbModel.TFlights2"
}, ID: "2", Airline: "United", Price: "1300", StartLocation: "Frankfurt", Destination: "Hamburg", DepartureTime: "\/Date(1208278920000)\/", ArrivalTime: "\/Date(1208275200000)\/", Provider: "P02"
}, {
__metadata: {
uri: "http://dado-nb0/DataServiceWebApp/BestFlightService.svc/TFlights2(3)", type: "BestFlightDemoDbModel.TFlights2"
}, ID: "3", Airline: "Lufthansa", Price: "1400", StartLocation: "Frankfurt", Destination: "Hamburg", DepartureTime: "\/Date(1208369100000)\/", ArrivalTime: "\/Date(1208365200000)\/", Provider: "P02"
}, {
__metadata: {
uri: "http://dado-nb0/DataServiceWebApp/BestFlightService.svc/TFlights2(12)", type: "BestFlightDemoDbModel.TFlights2"
}, ID: "12", Airline: "Aeroflot", Price: "1400", StartLocation: "Frankfurt", Destination: "Hamburg", DepartureTime: "\/Date(1208538000000)\/", ArrivalTime: "\/Date(1208365200000)\/", Provider: "P02"
}
] }
Posted
Apr 15 2008, 01:43 PM
by
Damir Dobric