Package ch.bfh.sokoban.lib.jsonJava

Examples of ch.bfh.sokoban.lib.jsonJava.JSONArray


   * Add the database options for the php - file to a nameValuePair
   */
  private static void addOptions(Options options)
  {
    jsonObject = new JSONObject();
    jsonArray = new JSONArray();

    try
    {
      jsonObject.put("query", options.getSql());
      jsonObject.put("usesInsertId", Boolean.toString(options.hasInsertId()));
View Full Code Here


   * @param inputStream has the returns from the database <br/>
   * @throws LazyException
   */
  private static void readReturnValues(LazyAnswer lazyAnswer, InputStream inputStream)
  {
    JSONArray jsonArr = null;   

    if(!lazyAnswer.hasError() && inputStream != null )
    {
      //convert response to string
      try
      {
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream,"utf-8"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        String result = "";

        while ((line = reader.readLine()) != null)
        {
          sb.append(line);
          //System.out.println("line: "+line);
        }

        inputStream.close();
        result=sb.toString();

        if(!result.equals("") && result.length()>0 && result.indexOf("[") != -1)
        {
          result = result.substring(result.indexOf("["),result.length());
          jsonArr = new JSONArray(result);
//          System.out.println("in#: "+jsonArr.toString());
          jsonArr = cryptor.jsonArrayDecrypt(jsonArr);
//          System.out.println("in: "+jsonArr.toString());
        }
        else
View Full Code Here

   *       {"id":"5","user":"15","article":"h7","quantity":"6"} <br />
   *       ...
   */
  private static void setLazyAnswer(LazyAnswer lazyAnswer, JSONArray jsonArr)
  {
    JSONArray jsonAnswer = new JSONArray();

    try
    {
      // Get the error message
      JSONObject obj = jsonArr.getJSONObject(0);
      lazyAnswer.setError(obj.getBoolean("exceptionFlag"));
      if(lazyAnswer.hasError()) {
        lazyAnswer.setErrorMessage(obj.getString("exceptionText"));
      }

      // Add the insertedId to the array if the user want it
      if(hasInsertedId)
        jsonAnswer.put(new JSONObject().put("insertedId", String.valueOf(obj.getInt("insertId"))));

      for(int i = 1; i < jsonArr.length(); i++)
      {
        obj = jsonArr.getJSONObject(i);
        jsonAnswer.put(obj);
      }
    }
    catch(JSONException e)
    {
      lazyAnswer.setError(true);
View Full Code Here

   * Encrypts keys and values of every JSONObject in a JSONArray
   * @param a The JSONArray to be encrypted
   * @return A JSONArray with encrypted keys and values
   */
  public JSONArray jsonArrayEncrypt(JSONArray a) {
    JSONArray returnArray = new JSONArray();

    for(int i = 0; i < a.length(); i++) {
      returnArray.put(this.jsonObjectEncrypt((JSONObject)a.get(i)));
    }

    return returnArray;
  }
View Full Code Here

   * Decrypts keys and values of every JSONObject in a JSONArray
   * @param a The JSONArray to be decrypted
   * @return A JSONArray with decrypted keys and values
   */
  public JSONArray jsonArrayDecrypt(JSONArray a) {
    JSONArray returnArray = new JSONArray();

    for(int i = 0; i < a.length(); i++) {
      returnArray.put(this.jsonObjectDecrypt((JSONObject)a.get(i)));
    }

    return returnArray;
  }
View Full Code Here

      System.out.println("Original: " + original);
      String encrypted = c.encrypt(original);
      System.out.println("Encoded: " + encrypted);
      System.out.println("Decoded: " + c.decrypt(encrypted));

      JSONArray arr = new JSONArray("[{\"id\"=\" 1 ʞ3 \"},{\"id\"=\"key\"}]");

      System.out.println(c.encrypt(arr.getJSONObject(1).getString("id")));

    } catch (JSONException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
View Full Code Here

   */
  public LazyAnswer()
  {
    hasError = false;
    errorMessage = "";
    returnValues = new JSONArray();
  }
View Full Code Here

TOP

Related Classes of ch.bfh.sokoban.lib.jsonJava.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.