I'm planning to create an iPhone search app. I type user type in the search string. The string will be searched by some search engines such as Google, Live, Yahoo ... I need to get search results in XML format. Is there any way to do this? help needed. please.
Thanks and relation, Shibin
A format returns a JSON XML There is a very highly stripped-down version of
Google does not make its SOAP interface available anymore, so I do not know that you will be able to get XML from them, at least one of the public interfaces I through. Fortunately for you, JSN responses are trivial to request and parsing on the iPhone.
You can issue a request with and you can parse JSON-formatted response on the iPhone.
For example, to create and submit a search request based on the example on Google AJAX page, you can enter You will create a If I follow this letter to Google's example, I will also add an API key for this URL. Google asks that you use the API key for REST searches, you must sign up for the API key and add it to your requests. You should also specify referee IP address in the request header, which will be the IP address of the local IP in this case, e.g. : There are asynchronous request management as outlined in the ASHTPPEEEEEE documentation. In any case, when you get Google's JSON-formatted response in hand, you can use JSN-Structure -requestWithURL
and -startSynchronous Methods you can use:
NSURL * searchURL = [NSURL URLWithString: @ "http://ajax.googleapis.com/ajax/services/search/web?v=1.0& ; Q = Paris% 20Hilton "]; ASHTTPRCEEEST * googleRequest = [ASIHTPPRquenta Request with url: searchURL]; [GoogleRequest addRequestHeader: @ "Referrer" value: [device itself ipadder]]; [GoogleRequest startSynchronous];
NSURL
example based on your search terms, request criteria. - (NSString *) deviceIPAddress {IRIP IIP [255]; Strcpy (iphoneIP, "127.0.0.1"); // if everything NSHost fails * myHost = [NSHost currentHost]; If (myHost) {NSString * address = [myHost address]; If (address) strcpy (IIIP, [address cStringUsingEncoding: NSUTF8StringEncoding]); } Return [NSString stringWithFormat: @ "% s", IIIIP]; }
SBJSON
to parse object by To parse the response in the NSDictionary
object:
NSError * requestError = [googleRequest error]; If (! Request Error) {SBJSON * jsonParser = [[SBJSon Alok] init]; NSString * googleResponse = [googleRequest feedback string]; NSDictionary * searchResults = [jsonParser objectwidth string: googleResponse error: zero]; [Json Parser Release]; // work with search. Results ...}
Comments
Post a Comment