Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用改型在android中使用xml解析_Android_Xml Parsing_Retrofit2 - Fatal编程技术网

如何使用改型在android中使用xml解析

如何使用改型在android中使用xml解析,android,xml-parsing,retrofit2,Android,Xml Parsing,Retrofit2,我是android新手,我想使用改型解析xml文件,我已经浏览了stackoverflow中发布的链接 但在我的场景中,我必须添加标题,我如何使用改型来实现这一点 下面是不带标题的xml解析器示例web服务: public interface ApiService { @GET("/webservice/xml") Call<YourClass> getXml(); } 要使用此代码,应将以下行添加到gradle文件中: compile 'com.squareup.

我是android新手,我想使用改型解析xml文件,我已经浏览了stackoverflow中发布的链接
但在我的场景中,我必须添加标题,我如何使用改型来实现这一点


下面是不带标题的xml解析器示例web服务:

public interface ApiService {
    @GET("/webservice/xml")
    Call<YourClass> getXml();
}
要使用此代码,应将以下行添加到gradle文件中:

compile 'com.squareup.retrofit2:retrofit:2.3.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
compile('com.squareup.retrofit2:converter-simplexml:2.1.0') {
    exclude group: 'xpp3', module: 'xpp3'
    exclude group: 'stax', module: 'stax-api'
    exclude group: 'stax', module: 'stax'
}

下面是一个很好的教程

示例界面,标题作为静态值:

public interface ApiService {

    @Headers("user-key: 9900a9720d31dfd5fdb4352700c")
    @GET("api/v2.1/search/webxml")
    Call<String> getRestaurantsBySearch(@Query("q"), String query);

}
公共接口服务{
@标题(“用户密钥:9900a9720d31dfd5fdb4352700c”)
@获取(“api/v2.1/search/webxml”)
调用getRestaurantsBySearch(@Query(“q”),字符串查询);
}

以标头作为参数的接口示例:

public interface ApiService {

    @GET("api/v2.1/search/webxml")
    Call<String> getRestaurantsBySearch(@Query("q"), String query, @Header("user-key") String userkey);

}
公共接口服务{
@获取(“api/v2.1/search/webxml”)
调用getRestaurantsBySearch(@Query(“q”)、字符串查询、@Header(“user key”)字符串userkey);
}

您可以使用标题发布示例代码吗?当我在获取响应时遇到nullpointerexception时,您可以查看一下吗?当我在获取响应时遇到nullpointerexception时,您可以查看一下吗
public interface ApiService {

    @Headers("user-key: 9900a9720d31dfd5fdb4352700c")
    @GET("api/v2.1/search/webxml")
    Call<String> getRestaurantsBySearch(@Query("q"), String query);

}
public interface ApiService {

    @GET("api/v2.1/search/webxml")
    Call<String> getRestaurantsBySearch(@Query("q"), String query, @Header("user-key") String userkey);

}