【发布时间】:2014-06-04 08:37:01
【问题描述】:
这是我的 JSON 数组,我无法从这个 JSON 数组中解析 ItemImage1 和 Bytes。
谁能帮帮我。
{"FetchAllItemsResult":[{"ItemID":5,
"ItemCategoryID":225,
"ItemCode":"1263",
"barcode":"0010000005",
"ItemDescription":"CAKE TRAY ROUND TEFAL 1 PCS (L) [RETAIL]",
"packingtypeid":1,
"ItemImage1":{"Bytes":[137,80,78,71,13,10,26,....]},
"sellingPrice":350.00,
"TaxPercentage":6.00},..]}
这是我的产品类别。
public class Product{
@SerializedName("ItemID")
int itemID;
@SerializedName("ItemCategoryID")
int itemCategoryID;
@SerializedName("ItemCode")
String itemCode;
@SerializedName("barcode")
String barCode;
@SerializedName("ItemDescription")
String itemDescription;
@SerializedName("packingtypeid")
int packingTypeID;
@SerializedName("sellingPrice")
double sellingPrice;
@SerializedName("TaxPercentage")
double taxPercentage;
@SerializedName("ItemImage1")
ProductImage itemImage;
}
这是 ProductImage 类。
public class ProductImage {
@SerializedName("Bytes")
byte[] itemImage;
}
这是保存整个 JSON 数组的 ProductList 类。
public class ProductList {
@SerializedName("FetchAllItemsResult")
List<Product> Products;
}
我正在使用VolleyGsonRequest<ProductList>
没有错误,但我无法从 JSON 数组中获取图像字节(ItemImage1 和 Bytes),请帮助我。
这是我得到的字节数组的输出。
[B@b2e761c8
【问题讨论】:
-
[B@b2e761c8看起来正确,因为[B表示字节数组。你的打印声明在哪里 -
我只是使用 getter 记录输出.. Log.i("ProductListReqImage", prod.getItemImage().getItemImage()+"");
-
Bytes 数组为您提供了看起来正确的对象地址。另一件事:为什么不使用某种字符串编码而不是将字节作为数组发送?
-
Log.i("ProductListReqImage", prod.getItemImage().getItemImage()[0]+"");应该给你 137。对吧?
-
这不是预期的。在最坏的情况下,您应该得到 ArrayOutOfBoundsException。请检查您的日志一次,看看某处是否有空值
标签: java android json gson android-volley