我已经做了REST Web服务,让我接触的一些信息,如号码,年龄......我得到所有这些信息,在此功能CodenameOne连接请求等待postResponse
public static void getRest(String search) {
if(search.equals("")){
json="http://localhost:8080/com.vogella.jersey.first/rest/jsonServices/print/";
} else {
json="http://localhost:8080/com.vogella.jersey.first/rest/jsonServices/print/"+search;
}
ConnectionRequest req = new ConnectionRequest() {
@Override
protected void postResponse() {
}
@Override
protected void readResponse(InputStream input) throws IOException {
JSONParser p = new JSONParser();
Map<String, Object> h = p.parseJSON(new InputStreamReader(input));
ArrayList object=new ArrayList();
for (Entry<String, Object> entry : h.entrySet()) {
object = (ArrayList) entry.getValue();
int i=object.size();
}
for(int i=0; i<object.size();i++){
LinkedHashMap s= (LinkedHashMap) object.get(i);
Risultati.add(s);
}
}
};
req.setUrl(json);
req.setPost(false);
req.addRequestHeader("Accept", "application/json");
InfiniteProgress prog = new InfiniteProgress();
Dialog dlg = prog.showInifiniteBlocking();
req.setDisposeOnCompletion(dlg);
NetworkManager.getInstance().addToQueue(req);
Risultati是的属性类:ArrayList<LinkedHashMap> Risultati;
的问题是,当我调用函数getRest("")
这样:
getRest("");
Label contatto=null;
for(int j=0;j<Risultati.size();j++){
LinkedHashMap s=Risultati.get(j);
String nome=(String) s.get("firstName");
String cognome=(String) s.get("lastName");
String numero =(String) s.get("numero");
contatto=new Label(nome+" "+cognome+" "+numero);
}
hi.addComponent(contatto);
事实是Risultati是空,如果我评论的周期我注意到内部函数readResponse执行后......我不知道我在做什么错
很好的答案。然而,一个挑剔的是,最后一段是不准确的。 addToQueueAndWait会在不阻塞UI线程的情况下“正确”阻止UI线程(是的,这就是禅),请参阅:http://www.codenameone.com/blog/callserially-the-edt-invokeandblock-part-1.html和http:/ /你确实需要展现无限进步或其他东西...... –