static public String handle(String request){
  StringBuilder response=new StringBuilder();
  JSONTokener tokener=new JSONTokener(request);
  try {
    Object token=tokener.nextValue();
    response.append("{");
    if (token instanceof JSONArray) {
      JSONArray array=(JSONArray)token;
      for (int i=0; i < array.length(); i++) {
        JSONObject object=(JSONObject)array.get(i);
        response.append("\"" + object.getString("action") + "\":");
        exec(object,response);
        if (i != array.length() - 1)         response.append(",");
      }
    }
 else     if (token instanceof JSONObject) {
      JSONObject object=(JSONObject)token;
      response.append("\"" + object.getString("action") + "\":");
      exec(object,response);
    }
    response.append("}");
  }
 catch (  Exception e) {
    Log.e(TAG,"Invalid request: " + request);
    e.printStackTrace();
    return "INVALID REQUEST";
  }
  Log.d(TAG,"Request: " + request);
  Log.d(TAG,"Answer: " + response.toString());
  return response.toString();
}

static public String handle ( String request ) { StringBuilder response = new StringBuilder ( ) ; JSONTokener tokener = new JSONTokener ( request ) ; try { Object token = tokener . nextValue ( ) ; response . append ( "{" ) ; if ( token instanceof JSONArray ) { JSONArray array = ( JSONArray ) token ; for ( int i = 0 ; i < array . length ( ) ; i ++ ) { JSONObject object = ( JSONObject ) array . get ( i ) ; response . append ( "\"" + object . getString ( "action" ) + "\":" ) ; exec ( object , response ) ; if ( i != array . length ( ) - 1 ) response . append ( "," ) ; } } else if ( token instanceof JSONObject ) { JSONObject object = ( JSONObject ) token ; response . append ( "\"" + object . getString ( "action" ) + "\":" ) ; exec ( object , response ) ; } response . append ( "}" ) ; } catch ( Exception e ) { Log . e ( TAG , "Invalid request: " + request ) ; e . printStackTrace ( ) ; return "INVALID REQUEST" ; } Log . d ( TAG , "Request: " + request ) ; Log . d ( TAG , "Answer: " + response . toString ( ) ) ; return response . toString ( ) ; }
executes a batch of requests and returns all the results
