How to connect to drupal 7 using web service?
Your use case can be achieved using Services module easily.

All you need to do is write a hook_service() 

refer http://drupal.org/node/118126 Or just look into the services module's any child module, may be user_services. 

Do this,


Write a service that exposes all your query parameters as fields.
Accept these parameters into your web service callback and perform your business logic.
Return your results, this is just a return statement, no JSON conversion here. 
ex: return $output. 
//$output contains your array or data structure that you have as a result of your queries.


Now, how to convert the data to JSON. ?

Services module will provide you intermediate servers,  XML-RPC, JSON. (these are by default, there are more avaialable on drupal.org). These servers function as end points to whom you can connect using external applications or entities. ex: http://www.domain.com/services/json.

Thats it, the flow will be,


You connect to the endpoint, URL http://www.domain.com/services/json. Pass the data in JSON.
the JSONserver will convert that into PHP and will pass it to your web service callback.
You do the processing and return the data to the web service in PHP.
The server converts the data into JSON again.
This is handed over to the HTTP request that requested the processing in the first place.