0
{
    "getRestorentList": {
        "status": "YES",
        "getRestorentList": [
            {
                "business_id": "93",
                "business_name": "Johnny's Steakhouse ",
                "description": "Johnny's Steakhouse , Is one of the best restaurant in our robust restaurant search engine. We help diners easily find the best restaurant for every occasion, every time from all cities in Germany from the most elegant restaurants for fine dining to casual, inexpensive spots for family meals, you'll find it all on 123gotit.com",
                "business_address": "Berliner Str. 28",
                "phone": "234-423-3242"
            },
            {
                "business_id": "94",
                "business_name": "Name of Restaurant",
                "description": "Name of Restaurant, Is one of the best restaurant in our robust restaurant search engine. We help diners easily find the best restaurant for every occasion, every time from all cities in Germany from the most elegant restaurants for fine dining to casual, inexpensive spots for family meals, you'll find it all on 123gotit.com",
                "business_address": "Address",
                "phone": "345-534-5345"
            }
        ]
    }
}

这是我的 json 数组

new golfSync().execute();
        ListView lv = getListView();


    }

    class golfSync extends AsyncTask<Void, Void, Void> {
        ArrayList<DataModel> listArray;
        JSONArray memeberListjsonArray;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(AtoZActivity.this);
            pDialog.setMessage("Loading Data ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {


            int datasize;
            JSONObject RegistrationResultJSONObject = null;
            ArrayList<NameValuePair> postParameters = null;
            try {
                postParameters = new ArrayList<NameValuePair>();
                Log.i("test", "abcccc");
                postParameters.add(new BasicNameValuePair("member_id",
                        "7"));


                RegistrationResultJSONObject = new JSONObject(
                        JsonParser.doFetchDataFromWebService(AppsUtility.getrestaurantlurl, "getRestorent",
                                postParameters));
                Log.i("members infohhhh", RegistrationResultJSONObject.toString());

                RegistrationResultJSONObject = RegistrationResultJSONObject
                        .getJSONObject("getRestorentList");
                if (RegistrationResultJSONObject.get("status").equals("YES")) {
                    memeberListjsonArray = RegistrationResultJSONObject
                            .getJSONArray("getRestorentList");

                    datasize = memeberListjsonArray.length();
                     HashMap<String, String> map = new HashMap<String, String>();
                    Log.i("Data Array Size", datasize + "");
                    listArray = new ArrayList<DataModel>(datasize);
                    for (int i = 0; i < datasize; i++) {

                        JSONObject dataobj = memeberListjsonArray
                                .getJSONObject(i);
                        Log.i("i", i + "");

                        String name = dataobj.getString("business_name");
                        Log.i("business_name", name);
                        String description = dataobj.getString("description");
                        Log.i("id", description);
                        String address = dataobj.getString("business_address");
                        Log.i("business_name", address);

                        // adding each child node to HashMap key => value
                        map.put("business_name", name);
                        map.put("description", description);
                        map.put("business_address", address);

                        RetailerList.add(map);


                    }
                //  arrayadapter = new ArrayAdapter<String>(GolfRetailerActivity.this, R.layout.list_golfretailer,R.id.retailername_tv, memberNameArray);

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

            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            pDialog.dismiss();
            // updating UI from Background Thread

            adapter = new SimpleAdapter(AtoZActivity.this,
                    RetailerList, R.layout.list_restaurant,
                    new String[] { "business_name","description","business_address"},
                    new int[] { R.id.restaurant_name_textView2,R.id.restaurant_description_textView3,R.id.restaurant_address_textView4 });
            // updating listview
            setListAdapter(adapter);
        }

这是我的最终代码

4

1 回答 1

0

使用 php 脚本查询数据库并输出到 JSON。抱歉,我不是 100% 确定问题是什么 这是一个教程 http://fahmirahman.wordpress.com/2011/04/21/connection-between-php-server-and-android-client-using-http-and- json/

于 2013-07-25T07:06:10.273 回答