hi,
you should encode your params I think:
StringBuffer params = new StringBuffer();
params.append("request=json");
params.append("&");
params.append("jsonData=");
params.append(URL.encodeComponent(elementSet.toString());
//
RequestBuilder rb = new RequestBuilder(RequestBuilder.POST,
SERVER_URL);
//
rb.sendRequest(params.toString(), new FormServerHandler());
//
also you seems to want to use JSON-RPC, which can be done that way:
JSONArray elements = new JSONArray();
for (int i = 0; i < 10; i++) {
JSONObject el1 = new JSONObject();
el1.put("sortid", new JSONNumber(1));
el1.put("label", new JSONString("Name"));
el1.put("name", new JSONString("name"));
el1.put("size", new JSONString("20"));
el1.put("maxLength", new JSONString("10"));
elements.set(i, el1);
}
JSONObject jsonRPC = new JSONObject();
jsonRPC.put("method", new JSONString("echo"));
jsonRPC.put("params", elements);
jsonRPC.put("id", new JSONNumber(9D));
//
RequestBuilder rb = null;
rb = new RequestBuilder(RequestBuilder.POST, SERVER_URL);
// CONTENT TYPE
rb.setHeader("Content-Type", "application/json");
rb.setHeader("Accept", "application/json");
//
Request r = null;
try {
r = rb.sendRequest(URL.encodeComponent(jsonRPC.toString()),
new RequestCallback() {
/* @Override */
public void onError(Request request, Throwable exception) {
// TODO Auto-generated method stub
}
/* @Override */
public void onResponseReceived(Request request,
Response response) {
// RESPONSE IN JSON should look like:
// {"result":{echoedJSONData, "error":..., "id":9}
String jsonData = response.getText();
JSONValue jsonResponse = JSONParser.parse(jsonData);
// TODO Auto-generated method stub
}
});
} catch (RequestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
on your server you can use any PHP JSON-RPC implementations (I've
checked and there are few written already),
on client you can either use GWT JSON implementation or use library
suggested by Miroslav to bind/build JSON objects,
regards
Peter