コード例 #1
0
ファイル: Json2JavaTest.java プロジェクト: RainerJava/shop-3
 public static void testJson2Java2() {
   String productImageListStore =
       "[{\"bigProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1_big.jpg\",\"id\":\"b955bd91c8b64844b4681b2eb44849d1\",\"smallProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1_small.jpg\",\"sourceProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1.jpeg\",\"thumbnailProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1_thumbnail.jpg\"}]";
   JsonConfig jsonConfig = new JsonConfig();
   jsonConfig.setRootClass(ProductImage.class);
   JSONArray jsonArray = JSONArray.fromObject(productImageListStore);
   List<ProductImage> list = (List<ProductImage>) JSONSerializer.toJava(jsonArray, jsonConfig);
   for (ProductImage p : list) {
     System.out.println(p.getBigProductImagePath());
   }
 }
コード例 #2
0
ファイル: Json2JavaTest.java プロジェクト: RainerJava/shop-3
  public static void testJson2Java() {
    String productImageListStore =
        "[{\"bigProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1_big.jpg\",\"id\":\"b955bd91c8b64844b4681b2eb44849d1\",\"smallProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1_small.jpg\",\"sourceProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1.jpeg\",\"thumbnailProductImagePath\":\"/upload/image/201307/b955bd91c8b64844b4681b2eb44849d1_thumbnail.jpg\"}]";
    JSONArray jsonArray = JSONArray.fromObject(productImageListStore);
    List productImageList = (List) JSONSerializer.toJava(jsonArray);

    // JSONObject.toBean(p, ProductImage.class);
    for (Object o : productImageList) {
      JSONObject jsonObject = JSONObject.fromObject(o);
      ProductImage obj = (ProductImage) JSONObject.toBean(jsonObject, ProductImage.class);
      System.out.println(obj.getBigProductImagePath());
    }
  }