示例#1
0
  public static Vector fromJsonArray(String jsonArray) {
    Vector vectorFacturas = new Vector();
    try {
      JSONArray array = new JSONArray(jsonArray);
      for (int i = 0; i < array.length(); i++) {
        JSONObject json = array.getJSONObject(i);
        Facturas fac = Facturas.fromJson(json.toString());

        vectorFacturas.addElement(fac);
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }
    return vectorFacturas;
  }
示例#2
0
  public void unserializeJSON(JSONArray a) throws JSONException {

    Vector v = new Vector();

    //  Mandatory fields

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

      JSONObject o = a.getJSONObject(i);
      Contact c = new Contact();
      c.unserializeJSON(o.getJSONObject("contact"));
      v.addElement(c);
    }

    contacts = new Contact[v.size()];
    v.copyInto(contacts);
  }
  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);
  }
示例#4
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);
  }
    public Object convertToUseForm(Object key, byte[] bytes) {
      JSONObject responseJson;

      try {
        responseJson = new JSONObject(new String(bytes));
      } catch (JSONException ex) {
        // #debug
        L.e("bytes are not a JSON object", featURL, ex);
        return null;
      }

      JSONArray entries = new JSONArray();
      final Vector vector = new Vector();

      try {
        final JSONObject feed = ((JSONObject) responseJson).getJSONObject("feed");
        entries = feed.getJSONArray("entry");
      } catch (JSONException e) {
        vector.addElement(new PicasaImageObject("No Results", "", "", ""));

        // #debug
        L.e("JSON no result", featURL, e);
      }

      for (int i = 0; i < entries.length(); i++) {
        try {
          final JSONObject jsonObject = entries.getJSONObject(i);
          final String title = jsonObject.getJSONObject("title").getString("$t");
          final String author =
              jsonObject
                  .getJSONArray("author")
                  .getJSONObject(0)
                  .getJSONObject("name")
                  .getString("$t");
          final String thumbUrl =
              jsonObject
                  .getJSONObject("media$group")
                  .getJSONArray("media$thumbnail")
                  .getJSONObject(0)
                  .getString("url");
          final String imageUrl =
              jsonObject
                  .getJSONObject("media$group")
                  .getJSONArray("media$content")
                  .getJSONObject(0)
                  .getString("url");

          // #mdebug
          L.i("JSON parsed title: ", title);
          L.i("JSON parsed author: ", author);
          L.i("JSON parsed thumb url: ", thumbUrl);
          L.i("JSON parsed image url: ", imageUrl);
          // #enddebug

          vector.addElement(new PicasaImageObject(title, author, thumbUrl, imageUrl));
        } catch (JSONException e) {
          // #debug
          L.e("JSON item parse error", featURL, e);
        }
      }

      if (entries.length() == 0) {
        vector.addElement(new PicasaImageObject("No Results", "", "", ""));
      }

      return vector;
    }