0

Im newbie in using JSON

{
  "orders": [
    {
      "id": "12",
      "ord_name": "Passion Fruit",
      "ord_desc": "Cold passion fruit",
      "ord_price": "75",
      "ord_qty": "3",
      "customer_id": "54feec24bff73",
      "ord_num": "13191554feec24bff73",
      "price_x_quan": "225.00",
      "image": "http:\/\/192.168.43.52\/MMOS\/uploads\/passion-fruit.jpg",
      "subtotal": "",
      "imgimg": "uploads\/passion-fruit.jpg"
    },
    {
      "id": "13",
      "ord_name": "Caramel Mocha",
      "ord_desc": "Cold caramel mocha",
      "ord_price": "100",
      "ord_qty": "1",
      "customer_id": "54feec24bff73",
      "ord_num": "13191554feec24bff73",
      "price_x_quan": "100.00",
      "image": "http:\/\/192.168.43.52\/MMOS\/uploads\/caramelmocha.jpg",
      "subtotal": "",
      "imgimg": "uploads\/caramelmocha.jpg"
    }
  ],
  "o_total": 325
}

'Im done parsing the array orders.

What I want now is to parse the o_total and put it on a TextView . Any idea how to do this?

This is how i did in the first array = 'orders' which is displayed on a listview

try {
                // Locate the array name in JSON==
                jsonarray = jsonobject.getJSONArray("orders");


            for (int i = 0; i < jsonarray.length(); i++) {
                    HashMap<String, String> map = new HashMap<String, String>();
                    jsonobject = jsonarray.getJSONObject(i);

                    // Retrive JSON Objects

                    map.put("id", jsonobject.getString("id"));
                    map.put("ord_name", jsonobject.getString("ord_name"));
                    map.put("ord_price", jsonobject.getString("ord_price"));
                    map.put("ord_qty", jsonobject.getString("ord_qty"));
                    map.put("customer_id", jsonobject.getString("customer_id"));
                    map.put("ord_num", jsonobject.getString("ord_num"));
                    map.put("price_x_quan", jsonobject.getString("price_x_quan"));
                    map.put("image", jsonobject.getString("image"));
                    map.put("text_ordernumber",home_in.getStringExtra("text_ordernumber"));
                    map.put("text_name",home_in.getStringExtra("text_name"));

                    // Set the JSON Objects into the array
                    arraylist.add(map);


                }


            } catch (JSONException e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }

i wonder how to do it on "o_total"

Rose_xxi
  • 13
  • 5

2 Answers2

0

I suppose you did something like this to get your array:

 JSONObject rootObject = new JSONObject(yourJSONString);
 rootObject.getJSONArray("order");

Just do the same to your "o_total":

 yourTextView.setText(rootObject.getString("o_total")); 
vinitius
  • 3,212
  • 2
  • 17
  • 22
0

Just do:

int o_total = jsonobject.get("o_total").getAsInt();
Siri0S
  • 678
  • 1
  • 6
  • 10