注意的有几点,hosted模式下RequestBuilder读取server的json有问题,用本地文件代替即可。 Zend_Json默认输出的json数据不能被读取,必须加[和]... echo "["; echo Zend_Json::encode($myconfig); echo "]"; 简单读取json的例子: package com.esbrain.client; import com.esbrain.shared.FieldVerifier; import com.google.gwt.core.client.EntryPoint; import com.google.gwt.core.client.GWT; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.event.dom.client.KeyCodes; import com.google.gwt.event.dom.client.KeyUpEvent; import com.google.gwt.event.dom.client.KeyUpHandler; import com.google.gwt.user.client.rpc.AsyncCallback; import com.google.gwt.user.client.ui.Button; import com.google.gwt.user.client.ui.DialogBox; import com.google.gwt.user.client.ui.HTML; import com.google.gwt.user.client.ui.Label; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.TextBox; import com.google.gwt.user.client.ui.VerticalPanel; import com.google.gwt.user.client.Window; import com.google.gwt.http.client.Request; import com.google.gwt.http.client.Response; import com.google.gwt.http.client.RequestCallback; import com.google.gwt.http.client.RequestBuilder; import com.google.gwt.http.client.RequestException; import com.google.gwt.http.client.URL; import com.google.gwt.json.client.*; /** * Entry point classes define <code>onModuleLoad()</code>. */ public class mygwt implements EntryPoint { String MY_URL = "http://feeds.feedburner.com/jandan?format=xml"; final private Button btn = new Button(); private static final RequestBuilder reqBuilder = new RequestBuilder( RequestBuilder.GET , "/my.json" //"http://localhost/ecshop/public/rdcfg/base" ); private class SendButtonHandler implements ClickHandler{ public void onClick(ClickEvent ce){ try{ reqBuilder.sendRequest(null, new RequestCallback(){ public void onError(Request req , Throwable t){ Window.alert("get error"); Window.alert(t.getMessage().toString()); } public void onResponseReceived(Request req , Response response){ if (response.getStatusCode() == 200){ Window.alert(response.getText()); Window.alert("start to parse json now..."); JSONValue jsonValue = JSONParser.parse(response.getText()); JSONArray array = jsonValue.isArray(); for (Integer i=0; i<array.size();i++){ JSONObject jobject = array.get(i).isObject(); Window.alert(jobject.get("sitename").toString()); } } } }); } catch(RequestException e) { Window.alert("run time error"); Window.alert(e.getMessage().toString()); } } } public void onModuleLoad(){ btn.addClickHandler(new SendButtonHandler()); btn.setText("send request"); RootPanel.get().add(btn); } }