コード例 #1
0
ファイル: JsonComparator.java プロジェクト: Jaxo/jaxogram
  @SuppressWarnings("rawtypes")
  private boolean isEqualsJsonObject(JSONObject a, JSONObject b) {
    if (policy == STRICT) {
      if (a.length() != b.length()) {
        return false;
      }
    }

    if (policy == SIMPLE) {
      if (a.length() > b.length()) {
        return false;
      }
    }

    Enumeration keys = a.keys();
    while (keys.hasMoreElements()) {
      String key = (String) keys.nextElement();
      if (!b.has(key)) {
        return false;
      }
      try {
        if (!isEquals(a.get(key), b.get(key))) {
          return false;
        }
      } catch (JSONException e) {
        return false;
      }
    }

    return true;
  }
コード例 #2
0
  public void descargarDatos() {

    try {

      connectionURL = Strings.HTTP_SW + "getMunicipios/" + tipoConexion;

      // Dialog.alert(connectionURL+"<<URL");

      conn = (HttpConnection) Connector.open(connectionURL);
      conn.setRequestProperty("Content-Type", "application/json");
      // System.out.println("Response code : "+conn.getResponseCode());

      if (conn.getResponseCode() == HttpConnection.HTTP_OK) {

        is = conn.openInputStream();
        int ch = -1;
        bos = new ByteArrayOutputStream();
        while ((ch = is.read()) != -1) {
          bos.write(ch);
        }
        response = new String(bos.toByteArray(), "UTF-8");

        // JSONObject temporalError = new  JSONObject ( response );

        // errorCode    = temporalError.getString("errotCode");
        // errorMessage = temporalError.getString("errorMessage");

        JSONObject objeto1 = new JSONObject(response);
        String resultado1 = objeto1.getString("response");
        // Dialog.alert(resultado1+"<<");
        JSONObject objeto2 = new JSONObject(resultado1);
        errorCode = objeto2.getString("errorCode");
        errorMessage = objeto2.getString("errorMessage");

        if (errorCode.equals("0")) {

          JSONArray jsonMainArr = objeto2.getJSONArray("msg");

          for (int i = 0; i < jsonMainArr.length(); i++) {

            JSONObject childJSONObject = jsonMainArr.getJSONObject(i);

            IdMunicipio.addElement(childJSONObject.get("idMunicipio"));
            NombreMunicipio.addElement(childJSONObject.get("municipio"));
          }

        } else if (errorCode.equals("1")) {
          if (Display.getWidth() == 320) {
            errorMessage = "noData1_320.png";
          }
          if (Display.getWidth() == 360) {
            errorMessage = "noData1_360.png";
          }
          if (Display.getWidth() == 480) {
            errorMessage = "noData1_480.png";
          }
          if (Display.getWidth() == 640) {
            errorMessage = "noData1.png";
          }
        }
      }

    } catch (Exception e) {
      // TODO: handle exception
      if (Display.getWidth() == 320) {
        errorMessage = "noData1_320.png";
      }
      if (Display.getWidth() == 360) {
        errorMessage = "noData1_360.png";
      }
      if (Display.getWidth() == 480) {
        errorMessage = "noData1_480.png";
      }
      if (Display.getWidth() == 640) {
        errorMessage = "noData1.png";
      }
    } finally {
      if (conn != null)
        try {
          conn.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      if (is != null)
        try {
          is.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      if (bos != null)
        try {
          bos.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
    }
    municipiocompras.setIdMunicipio(IdMunicipio);
    municipiocompras.setNombreMunicipio(NombreMunicipio);

    municipiocompras.seterrorCode(errorCode);
    municipiocompras.seterrorMessage(errorMessage);
  }
コード例 #3
0
  public SearchProductoCx(int idcategoria, String PalabraFiltro) {

    SearchProductoSG searchproducto = new SearchProductoSG();

    try {

      connectionURL =
          Strings.HTTP_SW
              + "getListaDeProductosPorCategoriaPorNombre/"
              + idcategoria
              + "/"
              + PalabraFiltro
              + tipoConexion;

      conn = (HttpConnection) Connector.open(connectionURL);
      conn.setRequestProperty("Content-Type", "application/json");
      // System.out.println("Response code : "+conn.getResponseCode());

      if (conn.getResponseCode() == HttpConnection.HTTP_OK) {

        is = conn.openInputStream();
        int ch = -1;
        bos = new ByteArrayOutputStream();
        while ((ch = is.read()) != -1) {
          bos.write(ch);
        }
        response = new String(bos.toByteArray(), "UTF-8");

        JSONObject objeto1 = new JSONObject(response);
        String resultado1 = objeto1.getString("response");

        JSONObject objeto2 = new JSONObject(resultado1);
        errorCode = objeto2.getString("errorCode");
        errorMessage = objeto2.getString("errorMessage");

        JSONArray jsonMainArr = objeto2.getJSONArray("msg");

        for (int i = 0; i < jsonMainArr.length(); i++) {

          JSONObject childJSONObject = jsonMainArr.getJSONObject(i);

          IdProducto.addElement(childJSONObject.get("idProducto"));
          Nombre.addElement(childJSONObject.get("nombre"));
        }
      }

    } catch (Exception e) {
      // TODO: handle exception
    } finally {
      if (conn != null)
        try {
          conn.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      if (is != null)
        try {
          is.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
      if (bos != null)
        try {
          bos.close();
        } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
    }

    searchproducto.setIdProducto(IdProducto);
    searchproducto.setNombre(Nombre);
    searchproducto.seterrorCode(errorCode);
    searchproducto.seterrorMessage(errorMessage);
  }