コード例 #1
0
  protected void onPostExecute(String result) {
    super.onPostExecute(result);
    progressDialog.dismiss();

    Log.i("TAG", "onPostExcecute");
    Log.i("TAG", String.valueOf(similarProductListDTO.size()));
    Log.i("TAG", String.valueOf(productDetailDTO.imagePath));

    similarProductListView.setAdapter(
        new SimilarProductListAdapter(context, similarProductListDTO, imageLoader, options));

    productName.setText(productDetailDTO.getPdtName());
    productType.setText(productDetailDTO.getPdtType());
    productBrandDetail.setText(productDetailDTO.getPdtBrand());
    productFeaturePrice.setText(productDetailDTO.getPdtFeaturedPrice());
    productFeatureDecimalPrice.setText("00");
    productPrice.setText(productDetailDTO.getPdtPrice());
    productDecimalPrice.setText("00");
    productAvailable.setText(productDetailDTO.getIsStockout());
    productDesc.setText(productDetailDTO.getPdtDesc());

    imageLoader.displayImage(productDetailDTO.getImagePath(), productImageView, options);

    //		((Activity) context).runOnUiThread(new Runnable(){
    //		    public void run(){
    //		        imageLoader.displayImage(productDetailDTO.getImagePath(), productImageView,
    // options);
    //		        Log.i("TAG", "ImagePath"+":"+String.valueOf(productDetailDTO.imagePath)+ " "
    //		        +"ImageView"+ productImageView
    //		        		);
    //		    }
    //		});
  }
コード例 #2
0
  /*
   * Parse JSON with JackSON Parser directly into Java Objects
   */
  @SuppressWarnings("deprecation")
  public void parseJSON() throws JsonParseException, IOException {
    JsonFactory f = new JsonFactory();
    boolean breakLoop = false;
    boolean breakOuterLoop = false;
    boolean emptySimilarProduct = true;
    JsonParser jp = null;
    try {
      //				jp = f.createJsonParser(context.getAssets().open("kadajsondata.txt"));
      jp =
          f.createJsonParser(
              RestClient.connect(
                  AppConstants.URLS.PRODUCT_DETAIL_URL
                      + urlProductId
                      + "&intProductVersionId="
                      + urlVersionId));
    } catch (JsonParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    while (jp.nextToken() != JsonToken.END_ARRAY) {
      if (breakOuterLoop) {
        break;
      }
      String fieldname = jp.getCurrentName();
      if ("ProductDetails".equals(fieldname)) {
        while (jp.nextToken() != JsonToken.END_ARRAY) {
          //						if ("}".equals(jp.getText())) {
          //							productDetailDTO = new ProductDetailDTO();
          //						}
          if (jp.getText().equals(JsonToken.END_OBJECT)) {
            break;
          }

          String responsefield = jp.getCurrentName();
          jp.nextToken(); // move to value

          if ("pdtId".equals(responsefield)) {
            productDetailDTO.setPdtId(jp.getText());
          } else if ("versionId".equals(responsefield)) {
            productDetailDTO.setVersionId(jp.getText());
          } else if ("pdtName".equals(responsefield)) {
            productDetailDTO.setPdtName(jp.getText());
          } else if ("isFeatured".equals(responsefield)) {
            productDetailDTO.setIsFeatured(jp.getText());
          } else if ("pdtFeaturedPrice".equals(responsefield)) {
            productDetailDTO.setPdtFeaturedPrice(jp.getText());
          } else if ("pdtPrice".equals(responsefield)) {
            productDetailDTO.setPdtPrice(jp.getText());
          } else if ("isStockout".equals(responsefield)) {
            productDetailDTO.setIsStockout(jp.getText());
          } else if ("isLimited".equals(responsefield)) {
            productDetailDTO.setIsLimited(jp.getText());
          } else if ("pdtBrand".equals(responsefield)) {
            productDetailDTO.setPdtBrand(jp.getText());
          } else if ("pdtDesc".equals(responsefield)) {
            productDetailDTO.setPdtDesc(jp.getText());
          } else if ("pdtType".equals(responsefield)) {
            productDetailDTO.setPdtType(jp.getText());
          } else if ("isFoodCoupon".equals(responsefield)) {
            productDetailDTO.setIsFoodCoupon(jp.getText());
          } else if ("stockAvailable".equals(responsefield)) {
            productDetailDTO.setStockAvailable(jp.getText());
          } else if ("imagePath".equals(responsefield)) {
            productDetailDTO.setImagePath(jp.getText());
          } else if ("SimilarProducts".equals(responsefield)) {
            jp.nextToken();
            if (jp.getText().equals("]")) {
              emptySimilarProduct = false;
              jp.nextToken();
              String responseImagePath = jp.getCurrentName();
              jp.nextToken(); // move to value
              if ("imagePath".equals(responseImagePath)) {
                productDetailDTO.setImagePath(jp.getText());
              }
            }
            while (jp.nextToken() != JsonToken.END_ARRAY && emptySimilarProduct) {
              if ("}".equals(jp.getText())) {
                similarProductListDTO.add(similarProductDTO);
                similarProductDTO = new SimilarProductDTO();
              }
              if (jp.getText().equals(JsonToken.END_OBJECT)) {
                break;
              }

              String responsefield1 = jp.getCurrentName();
              jp.nextToken(); // move to value

              if ("pdtId".equals(responsefield1)) {
                similarProductDTO.setPdtId(jp.getText());
              } else if ("versionId".equals(responsefield1)) {
                similarProductDTO.setVersionId(jp.getText());
              } else if ("pdtName".equals(responsefield1)) {
                similarProductDTO.setPdtName(jp.getText());
              } else if ("isFeatured".equals(responsefield1)) {
                similarProductDTO.setIsFeatured(jp.getText());
              } else if ("pdtFeaturedPrice".equals(responsefield1)) {
                similarProductDTO.setPdtFeaturedPrice(jp.getText());
              } else if ("pdtPrice".equals(responsefield1)) {
                similarProductDTO.setPdtPrice(jp.getText());
              } else if ("isStockout".equals(responsefield1)) {
                similarProductDTO.setIsStockout(jp.getText());
              } else if ("isLimited".equals(responsefield1)) {
                similarProductDTO.setIsLimited(jp.getText());
              } else if ("isFoodCoupon".equals(responsefield1)) {
                similarProductDTO.setIsFoodCoupon(jp.getText());
              } else if ("stockAvailable".equals(responsefield1)) {
                similarProductDTO.setStockAvailable(jp.getText());
              } else if ("imagePath".equals(responsefield1)) {
                similarProductDTO.setImagePath(jp.getText());
              } else if (jp.getText().equals("]")) {
                Log.i("Jackson", "Outta Similar Products");
                breakLoop = true;
                break;
              } else {
                Log.i("Jackson", "Unrecognized Token");
              }
            }
          } else if (jp.getText().equals("]")) {
            Log.i("Jackson", "Outta ProductDetail");
            breakOuterLoop = true;
            break;
          } else {
            Log.i("Jackson", "Unrecognized Token");
          }
        }
      }
    }
    jp.close();
  }