Q:

JSON response not fetched by obj.getJSONArray

I am trying to fetch a response from PHP containing latitudes and longitudes, so after those coordinates are received by my app, it should add markers according to those on map. The JSON response is a valid one, according to JSONlint, but the app doesn't seem to want to add the markers.
.java code for retrieving JSON response:
@Override
        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            //hiding the progressbar after completion

            try {
                //converting response to json object
                JSONObject obj = new JSONObject(s);

                //if no error in response
                if (!obj.getBoolean("error")) {
                    Toast.makeText(getApplicationContext(), obj.getString("message"), Toast.LENGTH_SHORT).show();

                    JSONArray locatieArray = obj.getJSONArray("locatie");
                    for (int i = 0; i < locatieArray.length(); i++) {
                        JSONObject locatie = locatieArray.getJSONObject(i);
                        // check latitudine and longitudine is not null and if not null then cast these values and call the addMarker() method.
                        if(!locatie.isNull("latitudine") && !locatie.isNull("longitudine")) {
                            latitudine_sql =Double.valueOf(locatie.getString("latitudine"));
                            longitudine_sql = Double.valueOf(locatie.getString("longitudine"));
                            addMarker(latitudine_sql, longitudine_sql); // this method is implemented below
                        }
                        tip_problema_sql = locatie.getString("tip_problema");
                    }

                } else {
                    Toast.makeText(getApplicationContext(), "Some error occurred", Toast.LENGTH_SHORT).show();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

.php sending the response: 
$problema = $_POST['problema'];

            $stmt = $conn->prepare("SELECT latitudine, longitudine, tip_problema FROM alerte WHERE tip_problema = ?");
            $stmt->bind_param("s", $problema);
            $stmt->execute();
            $stmt->store_result(); 
            $i = 0;
            if($stmt->num_rows > 0){
                $stmt->bind_result($latitudine, $longitudine, $tip_problema);

                while($stmt->fetch()) {
                    $i++;
                    $locatie = array(
                        'latitudine'=>$latitudine,
                        'longitudine'=>$longitudine,
                        'tip_problema'=>$tip_problema
                        );

            $response['error'] = false; 
            $response['message'] = 'Alerta raportata';
            $response['locatie'][$i] =$locatie;    
            }
            }else{
                $response['error'] = true; 
                $response['message'] = 'Eroare de identificare a alertelor';
            }

JSON response retrieved by app :
{
"error": false,
"message": "Alerta raportata",
"locatie": {
    "1": {
        "latitudine": 37.4254,
        "longitudine": -122.08,
        "tip_problema": "Semafor nefunctional"
    },
    "2": {
        "latitudine": 37.4259,
        "longitudine": -122.088,
        "tip_problema": "Semafor nefunctional"
    },
    "3": {
        "latitudine": 37.4259,
        "longitudine": -122.088,
        "tip_problema": "Semafor nefunctional"
    },
    "4": {
        "latitudine": 37.4207,
        "longitudine": -122.085,
        "tip_problema": "Semafor nefunctional"
    }
}

}

A:

like demo:
<?php 

// Declare two dimensional associative 
// array and initilize it 
$arr['locatie'] [] = array ( 
    1=>array( 
        "latitudine"=>1, 
        "longitudine"=>"Doorbell", 
        "tip_problema"=>199 
    ), 
    2=>array( 
        "latitudine"=>2, 
        "longitudine"=>"Bottle", 
        "tip_problema"=>99 
    ), 
    3=>array( 
        "latitudine"=>3, 
        "longitudine"=>"Washing Machine", 
        "tip_problema"=>7999 
    )
); 

// Function to convert array into JSON 
echo json_encode($arr); 

?> 

Output:
{"locatie":[{"1":{"latitudine":1,"longitudine":"Doorbell","tip_problema":199},"2":{"latitudine":2,"longitudine":"Bottle","tip_problema":99},"3":{"latitudine":3,"longitudine":"Washing Machine","tip_problema":7999}}]} 

Please set as per your requirement of the array value like : latitudine,longitudine,tip_problema use foreach loop to generate it.
I hope it'll help you...!

