JSon oData

Aug 4, 2011 at 9:13 AM

hi,

How to add a json stream from the oData Client for Objective-C?

I try it with jQuery an it's work.

But in Objective-C I try to add a personnal header :

DataModel *proxy = [[DataModel alloc] initWithUri:@"http://www.example.com/odata/odata.svc" credential:nil];
[proxy addHeader:@"Accept" headerValue:@"application/json, text/javascript, */*; sq=0.01"];
QueryOperationResponse *response = [proxy execute:@"Example"];
NSMutableArray *array = [response getResult];

This didn't work...

how to do it?

thank

Gwennin

Jan 10, 2012 at 6:35 AM

Hi,

I m also having the same problem.Have anybody got the solution?

 

 

Jan 26, 2012 at 3:17 PM
Edited Jan 26, 2012 at 3:19 PM

Finded!

You had to rewrite a JSon Parser compatible with an OData JSon Stream,

Add it to the library.

Modify the

 +(NSMutableDictionnary*)CreateHeaders:(NSString*) 
                                  eTag:(NSString*) 
                   ODataServiceVersion:(NSString*); 

method to add JSon Support with this header:

Accept: application/json,text/javascript

And it will work (I haven't tried, it's too loose time for me).

The CreateHeaders method is called from

-(HTTPHandler*)executeHTTPRequest:(NSSTring*) 
		     httpmethod:(NSString*) 
		   httpbodydata:(NDData*) 
			  etag:(NSString*) 
		  customHeaders:(NSMutableDictionary*)

Note: if you want to add support of custom headers request you should pass a non nil value to this method in :

-(HTTPHandler*)executeHTTPRequest:(NSString*)
                       httpmethod:(NSString*) 
                     httpbodydata:(NDData*)
                             etag:(NSString*)

This three methods are in the ObjectContext class.

 

If I have time, I will fork the OData4ObjC on github to propose this correction.

Good luck.

Gwennin

Jan 26, 2012 at 4:04 PM
Thanks. Please give me a pull request if you do the fix. I would love to take these fixes into the library.

Arlo

Sent from my Windows Phone

From: Gwennin
Sent: 1/26/2012 8:17 AM
To: Arlo Belshee
Subject: Re: JSon oData [odataobjc:267696]

From: Gwennin

Finded!

You had to rewrite a JSon Parser compatible with an OData JSon Stream,

Add it to the library.

Modify the

 +(NSMutableDictionnary*)CreateHeaders:(NSString*) eTag(NSString*) ODataServiceVersion:(NSString*); 

method to add JSon Support with this header:

Accept: application/json,text/javascript

And it will work (I haven't tried, it's too loose time for me).

The CreateHeaders method is called from

-(HTTPHandler*)executeHTTPRequest:(NSSTring*) httpmethod:(NSString*) httpbodydata:(NDData*) etag:(NSString*) customHeaders:(NSMutableDictionary*)

Note: if you want to add support of custom headers request you should pass a non nil value to this method in :

-(HTTPHandler*)executeHTTPRequest:(NSSTring*) httpmethod:(NSString*) httpbodydata:(NDData*) etag:(NSString*)

This three methods are in the ObjectContext class.

If I have time, I will fork the OData4ObjC on github to propose this correction.

Good luck.

Gwennin