嘿,我有這個JSONarray,我想知道如何從數組中獲得值ProductName
,description
和cost
。從JSONArray獲取值
我用下面的方法來獲得例如像quantity
值:
quantitybasket.setText(basket.getString("quantity"));
當我試圖讓productName
的logcat
說ProductName
不包含任何價值。
我需要做些什麼來獲得這些值?
[{"id":4,"quantity":2,"product":{"id":2,"productName":"Audi R8","description":"The best of Audi","cost":1000000.0,"rrp":1500000.0,"product_category":[{"id":2,"category":{"id":1,"categoryname":"Supercars"}},{"id":3,"category":{"id":2,"categoryname":"Sportscars"}}]}}]
我在Android TextView
TextView productbasket = (TextView) productsListItem
.findViewById(R.id.product_name_basket);
TextView descriptionbasket = (TextView) productsListItem
.findViewById(R.id.description_basket);
TextView costbasket = (TextView) productsListItem
.findViewById(R.id.cost_basket);
TextView quantitybasket = (TextView) productsListItem
.findViewById(R.id.quantity_basket);
你如何反序列化JSON? –