将json数组对象传递给php

时间:2015-01-13 05:14:15

标签: php android mysql json

  private void populateSpinner() {
        List<String> list = new ArrayList<String>();
        list.add("Salary");
        list.add("Sales");
        list.add("Others");
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        dataAdapter.notifyDataSetChanged();
        spinner2.setAdapter(dataAdapter);

        List<String> lables = new ArrayList<String>();

          for (int i = 0; i < categoriesList.size(); i++) {
        lables.add(categoriesList.get(i).getName());
    }

    // Creating adapter for spinner
    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_spinner_item, lables);

    // Drop down layout style - list view with radio button
    spinnerAdapter
            .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // attaching data adapter to spinner
    spinner1.setAdapter(spinnerAdapter);
}





/**
 * Async task to get all food categories
 * */
private class GetCategories extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(CampaignStatus.this);
        pDialog.setMessage("Fetching values..");
        pDialog.setCancelable(false);
        pDialog.show();

    }

    @Override
    protected Void doInBackground(Void... arg0) {
        ServiceHandler jsonParser = new ServiceHandler();
        String json = jsonParser.makeServiceCall(URL_CATEGORIES, ServiceHandler.GET);
        Log.e("Response json: ", "> " + json);
          if (json != null) {
            try {
                JSONObject jsonObj = new JSONObject(json);
                if (jsonObj != null) {
                    JSONArray categ = jsonObj
                            .getJSONArray("categories");                       

                    for (int i = 0; i < categ.length(); i++) {
                        JSONObject catObj = (JSONObject) categ.get(i);
                        Category cat = new Category(catObj.getInt("id"),  //i need to pass this id//
                                catObj.getString("name"));
                        categoriesList.add(cat);
                        Object a=categoriesList.get(i);
                        System.out.print(a);
                    }
                }

            } catch (JSONException e) {
                e.printStackTrace();
            }


        } else {
            Log.e("JSON Data", "Didn't receive any data from server!");
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        if (pDialog.isShowing())
            pDialog.dismiss();
        populateSpinner();

            }

}

上面的android代码用于通过php(json编码)从mysql数据库填充微调器 我需要知道如何将json数组中提到的id传递给我的php。

我的PHP代码

<?php
    $hostname_localhost ="sks10";
    $database_localhost ="ccvv7";
    $username_localhost ="sks18";
    $password_localhost ="sks18";
    $localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
    or
    trigger_error(mysql_error(),E_USER_ERROR);
    mysql_select_db($database_localhost, $localhost);
    if (isset($_POST["campid"]))
        {
            $campid = $_POST["campid"];
            echo $campid;
            echo " is your name";
        }
        else
        {
            $campid = null;
            echo "no name supplied";
        }
    $query_search = "SELECT CRM_TASK_ID FROM CRM_COMPLETED_TASK WHERE CRM_CAMPAIGN_ID='.$campid.' AND CRM_FILTER_ID='1207' and
            crm_task_id not in (select crm_task_id from crm_completed_task where crm_campaign_id = '.$campid.' and crm_filter_id = '1207')
    and crm_task_id not in (select  distinct crm_task_id from crm_daily_stat_details where crm_daily_stat_id in (select crm_daily_stat_id from crm_daily_stat where crm_campaign_id = '.$campid.' and crm_filter_id = '1207') and crm_task_id not in 
                    (select crm_task_id from crm_daily_stat_details where crm_daily_stat_id in (select crm_daily_stat_id from crm_daily_stat where crm_campaign_id = '.$campid.'
                     and crm_filter_id = '1207' and crm_post_code_categ_id != 1000)))";
    $query_exec = mysql_query($query_search) or die(mysql_error());
    $rows = mysql_num_rows($query_exec);
    echo $rows;

?>

我的php总是返回没有提供的名字。如何通过json解码将campid从android端传递到php端(它是一个json对象)

我已经查看了与此例外相关的相关问题,但我仍然无法提出解决方案。

我无法将doinBackground函数中定义的json对象id传递给我的php变量$ campid。请回答简单

0 个答案:

没有答案