How to call the JSON object in Android

后端 未结 5 1260
小鲜肉
小鲜肉 2020-12-21 06:09

I am new to the android development. i am having the following android code to call the json

  try {

        JSONObject jsonObject = new JSONObject(resul         


        
5条回答
  •  鱼传尺愫
    2020-12-21 06:46

    Try this

    JSONObject jsonObject = new JSONObject(result);
    JSONArray jArray =json.getJSONArray("enterjsonarraynamehere");
    
    for (int i=0; i < jArray.length(); i++)
    {
        try {
            JSONObject oneObject = jArray.getJSONObject(i);
            // Pulling items from the array
            String cust= oneObject.getString("CUSTOMER_ID");
        } catch (JSONException e) {
            // Oops something went wrong
        }
    }
    

    Im assuming your json is something like this

    
        {
            "enterjsonarraynamehere": [
                {  "0":"1",
                   "CUSTOMER_ID":"1"
                },
                {   "0":"2",
                   "CUSTOMER_ID":"2"
                } 
            ],
            "count": 2
        }
    
    

提交回复
热议问题