Skip to content Skip to sidebar Skip to footer

JSON Data Parsing Error The Response From Server Becomes Null: Android

I am trying to fetch data from the server and then display it into the app. I have JSON data as, {'COLUMNS':['TIMEID','BRANCHID','COMPANYID','MON_O','TUE_O','WED_O','THU_O','FRI_O'

Solution 1:

Try this.....

JSONParser jsonParser = new JSONParser();
            jsonObject = jsonParser.getJSONFromUrl(url);
    
            try {
                user1 = jsonObject.getJSONArray("COLUMNS");
    
                for (int i = 0; i < user1.length(); i++) {
                    String value = (String) user1.get(i);
    
                    getList.add(value.toString());
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

Solution 2:

I observe your json response, i think whatever you are having in column json array there are nothing having string which you are getting thats why you are getting error,

In your response nothing having key value pair so its easy to get String.

so you should getString() instead of getJsonObject()

private void showJSON(String response) {
    String name = "";
    try {
        JSONObject jsonObject = new JSONObject(response);
        Log.d("TAG", jsonObject.toString());
        JSONArray result = jsonObject.getJSONArray(JSON_ARRAY);
        Log.d("TAG", result.toString());
        name = result.getString(index);
        Log.e(name,"datadtadattadtatadtat");
    } catch (JSONException e) {
        e.printStackTrace();
    }

index is basically json array index you can put it 0 or something and go for loop if you want.


Post a Comment for "JSON Data Parsing Error The Response From Server Becomes Null: Android"