вы можете отправлять данные в виде пакетов Json на устройство, а в устройстве анализировать пакеты JSON и получать доступ к данным.ваши вызовы к веб-сервису должны быть HTTP-вызовом, например, для клиента.
http: \ server \ metnod \ get_somedata? name = что-то
, и сервер должен запросить базу данных об этом параметреи отправить вам ответ как Джсон.проанализируйте json и получите ваши данные.
String url = "http:\\example.com\mycontroller\get_employee?id=2"
HttpPost httpPostRequest = new HttpPost(url);
StringEntity se;
se = new StringEntity(jsonObjSend.toString());
httpPostRequest.setEntity(se);
httpPostRequest.setHeader("Authorization", usercredential);
httpPostRequest.setHeader("Accept", "application/json");
httpPostRequest.setHeader("Content-type", "application/json");
long t = System.currentTimeMillis();
response = (HttpResponse) httpclient.execute(httpPostRequest);
Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis()-t) + "ms]");
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
instream = new GZIPInputStream(instream);
}
// convert content stream to a String
String resultString= convertStreamToString(instream);
Log.v(null, "resultString "+resultString);
instream.close();
// Transform the String into a JSONObject
if(resultString!=null){
jsonObjRecv = new JSONObject(resultString);
}
// Raw DEBUG output of our received JSON object:
Log.i(TAG,"<jsonobject>\n"+jsonObjRecv.toString()+"\n</jsonobject>");
return jsonObjRecv;
На стороне сервера у вас должен быть метод get_employee в контроллере mycontroller.в методе вы можете обработать запрос как обычный http-запрос и отправить ответ как json, например:
employee = Employee.find_by_id(params[:id])
@js_response = ActiveSupport::JSON.encode(employee)
respond_to do |format|
format.json { render :json => @js_response}
format.html
end
для CRUD, вам нужно создать различные методы с соответствующими параметрами, такими как delete_employee, update_employee и т. д., см. json.orgсоздать / разобрать JSON в Android