Java 放置API缺少的标记
我正在使用GooglePlacesAPI,并试图解析XML数据,以获得包括评级在内的许多信息。唯一的问题是,有时没有评级标签(如下所示)。我如何解决这个问题Java 放置API缺少的标记,java,android,xml-parsing,google-api,google-places-api,Java,Android,Xml Parsing,Google Api,Google Places Api,我正在使用GooglePlacesAPI,并试图解析XML数据,以获得包括评级在内的许多信息。唯一的问题是,有时没有评级标签(如下所示)。我如何解决这个问题 <name>Zari</name> <type>restaurant</type> <type>food</type> <type>establishment</type> <formatted_address>212-214 Ifi
<name>Zari</name>
<type>restaurant</type>
<type>food</type>
<type>establishment</type>
<formatted_address>212-214 Ifield Drive, Crawley, United Kingdom</formatted_address>
<geometry>
<location>
<lat>51.1218980</lat>
<lng>-0.2135630</lng>
</location>
</geometry>
<rating>3.3</rating>
</result>
<result>
<name>Happy Meeting</name>
<type>restaurant</type>
<type>food</type>
<type>establishment</type>
<formatted_address>
<geometry>
<location>
<lat>51.1161600</lat>
<lng>-0.1844890</lng>
</location>
</geometry>
</result>
<result>
Zari
餐厅
食物
建立
英国克劳莱市伊菲尔德大道212-214号
51.1218980
-0.2135630
3.3
欢聚
餐厅
食物
建立
51.1161600
-0.1844890
只需检查一下你是否拿到了配给。例如,如果您正在像这样解析数据
String temp=null;
int rating;
if (localName.equals("rating")){ //this code won't work if rating tag is
// not present thus temp will be null
temp = attributes.getValue("rating");
rating = Integer.parseInt(temp);
}
现在在代码中进一步检查
if(temp==null){
rating=0; //or any that you want
}