我正在解析 Google 的 Weather API,例如,使用以下代码解析给定位置的当前摄氏温度:
currentTempC = [[[[[parse nodesForXPath:@"/xml_api_reply/weather/current_conditions/temp_c" error:nil] objectAtIndex:0] attributeForName:@"data"] stringValue] integerValue];
不幸的是,Google 每隔一段时间就会做一些事情,并且我请求的 XML 位置存在,但里面的数据不存在,所以我不能只是错误检查 XML 路径是否存在。我需要检查 XML 中是否存在特定对象,如果缺少,则填写一些默认值或 nil。
我已经放弃了如何做到这一点,所以我希望有人可以在这里给我一些帮助。我正在使用 TouchXML FWIW。