【问题标题】:Places API missing tag AndroidPlaces API 缺少标签 Android
【发布时间】:2013-01-25 20:57:11
【问题描述】:

我正在使用 Google Places api,我正在尝试解析 XML 数据以获取包括评级在内的许多信息。唯一的问题是有时没有评级标签(如下所示)。我该如何解决这个问题?

<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>

【问题讨论】:

    标签: java android xml-parsing google-api google-places-api


    【解决方案1】:

    只需检查您是否收到口粮。例如。如果您正在解析这样的数据

        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
    }
    

    【讨论】:

      猜你喜欢
      • 2015-07-24
      • 1970-01-01
      • 2015-10-12
      • 2013-06-26
      • 2020-10-27
      • 1970-01-01
      • 2023-03-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多