如何在php服务器上接收JSON对象

My Android app needs to send data to PHP server. I am new to PHP and don't know how to receive JSON and decode object at server. It would be great help if anyone can give me start up.

JSONObject json = new JSONObject();

try 
{
    json.put("dog", "cat");
} 
catch (JSONException e1) 
{
    // TODO Auto-generated catch block
    e1.printStackTrace();
}

HttpURLConnection urlConnection = null;
try 
{
    URL url = new URL("http://10.0.2.2/server.php");
    urlConnection = (HttpURLConnection)url.openConnection();
    urlConnection.setRequestProperty("Content-Type", "application/json");
    urlConnection.setRequestProperty("Accept", "application/json");
    urlConnection.setRequestMethod("POST");         
    urlConnection.setDoOutput(true);
    OutputStreamWriter os = new OutputStreamWriter(urlConnection.getOutputStream(), "UTF-8");
    os.write(json.toString());
    os.close();
}

Some example. Your MyActivity class

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mylyout);

            new PostToServer().execute();

}

class PostToServer extends AsyncTask<String, String, String> {


    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(MyActivity.this);
        pDialog.setMessage(getString(R.string.progdata));
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }


    protected String doInBackground(String... args) {

        String cat = "mycat";
        String dog = "mydog";

        HttpParams httpParameters = new BasicHttpParams();

        HttpClient client = new DefaultHttpClient(httpParameters);
        client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1);
        client.getParams().setParameter("http.socket.timeout", 2000);
        client.getParams().setParameter("http.protocol.content-charset", HTTP.UTF_8);
        httpParameters.setBooleanParameter("http.protocol.expect-continue", false);
        HttpPost request = new HttpPost("http://yourserver/your.php);
        request.getParams().setParameter("http.socket.timeout", 5000);

        List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
        postParameters.add(new BasicNameValuePair("cat", cat));
        postParameters.add(new BasicNameValuePair("dog", dog));

        try {
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters, HTTP.UTF_8);
        request.setEntity(formEntity);

        HttpResponse response = client.execute(request);

        in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        StringBuffer sb = new StringBuffer("");
        String line = "";
        while ((line = in.readLine()) != null) {
            sb.append(line);
        }
        in.close();
        String result = sb.toString();

        String delimso = "[;]+";
        String[] resultxxx = result.split(delimso);

         if( resultxxx[0].equals("1")) {


            // successfully updated
            //to do some

        }else {

            // unsuccessfully updated
            //to do some
        }

             } catch (ClientProtocolException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();

              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();

                  }


        return null;
    }           



    protected void onPostExecute(String file_url) {
        // dismiss the dialog once product uupdated
        pDialog.dismiss();
    }
}

your.php script on server

<?php


$cat = $_POST['cat'];
$dog = $_POST['dog'];

   //login to database

   //mysql operations $resttt
$result = mysql_query("$resttt");

$res="0;0";
if($result) { $res="1;0"; }               



echo $res;
?>

Thank you all for helping me. I have worked on some code, and it is working.

PHP server script

    $msg = file_get_contents('php://input');
    $input = json_decode($msg,true);

Now at this point json object is stored in $input variable.