Question

im developing an iphone app using yahoo weather service ( i have a key ). i have 2 question :

  1. can i use it in my app for commercial use ( like posting my app in appstore for free or no )
  2. why the xml and json result are different : http://weather.yahooapis.com/forecastrss?w=29330057&u=c and http://weather.yahooapis.com/forecastjson?w=29330057&u=c

there is any thing to do to much ( the first have the wanted location )? thank you.

Was it helpful?

Solution

I suspect this is an issue with XML namespaces. Depending on the framework used and the actual full XML you'd have to access the elements by their namespace. You might want to switch to another, DOM-based framework (not using NSXMLParser), for example GDataXMLNode by Google. In a DOM-based framework you can access the individual nodes in a tree-like structure instead of building one on your own.

There are plenty of examples for this on the net, for example Building an RSS reader or How to read and write XML documents with GDataXML. But to give a quick example how this might look:

NSError *error = nil;
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:data options:0 error:&error];

if (doc == nil) { return nil; }

NSMutableDictionary *result = [[NSMutableDictionary alloc] init];

NSArray *lists = [doc nodesForXPath:@"/result/list" error:nil];
if ([lists count] > 0)
{
    for (GDataXMLNode *list in lists) {
        int listid = [self integerInNode:list forXPath:@"listid"];
        NSString *listname = [self stringInNode:list forXPath:@"name"];

        [result setValue:[NSNumber numberWithInt:listid] forKey:listname];   

    }     
}
[doc release];
return [result autorelease]; 

OTHER TIPS

  1. Yes, Yahoo! let you use their APIs under a fair-use policy, even commercially. Don’t be an ass and give them enough props though, e.g. their icon or logo with a link to their website.
  2. I don’t think that it’s important to know why there are differences in both output formats. Use what is better / easier for you. Personally I prefer using JSON and Apple’s NSJSONSerialization class.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top