2014-07-06 25 views
0

我有一个发送JSON类似于这样一个Web服务:如何检索带有android注释的JSON数组?

[ 
    "4.11.3", 
    "4.10.7", 
    "4.10.2", 
    "4.9.1" 
] 

我的REST接口看起来是这样的:

@Rest(...) 
public interface RestInterface { 

    @Get("...") 
    String[] getVersions(); 
} 

但我总是得到null作为返回值。请有人帮助我吗?

+0

我以前没有使用过REST API,但是我知道你必须添加一个转换器。你仔细阅读[this](https://github.com/excilys/androidannotations/wiki/Rest%20API)吗? – WonderCsabo

回答

0

添加到您的其余服务:

@Accept(MediaType.APPLICATION_JSON) 
+2

简短的解释为什么代码片段解决了这个问题,会增加响应的质量! –

0

您的JSON是包含字符串的长度为4的JSON阵列

所以....使用以下代码:

JSONArray versionJsonArray=new JSONArray(<web-service response>); 
String[] versionString=new String[versionJsonArray.length()]; 

for(int j=0;j<versionJsonArray.length();j++) 
    versionString[j]=versionJsonArray.getString(j); 
0
Rest(...) 
public interface RestInterface { 

@Get("...") 
    JSONArray getVersions(); 
} 

让剩下的适配器将字符串输入到一个json数组中。