get-jsonResponse在android中为空?

get-jsonResponse在android中为空?,android,jsonresponse,Android,Jsonresponse,在浏览器上运行URL时,我得到了正确的JSONResponse,但我已经运行了我的应用程序,然后jsonObject是Get null,在我的异步类中是System.out.println 实际上,我在编码方面的错误是什么?请建议我。因为我得到了正确的JSON响应 我的异步类使用了JSONFunctions类,URL是 我的JAVA代码是 public class CategoryFragment extends Fragment { JSONObject jsonobject = n

在浏览器上运行URL时,我得到了正确的JSONResponse,但我已经运行了我的应用程序,然后jsonObject是Get null,在我的异步类中是System.out.println

实际上,我在编码方面的错误是什么?请建议我。因为我得到了正确的JSON响应

我的异步类使用了JSONFunctions类,URL是

我的JAVA代码是

public class CategoryFragment extends Fragment {

    JSONObject jsonobject = null;
    JSONArray jsonarray = null;
    ProgressDialog progressDialog = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

            initializeWidgets(rootView);

            new GetData().execute();

        }
        return rootView;
    }

    public class GetData extends AsyncTask<Void, Void, Void> {

        protected void onPreExecute() {
            progressDialog = new ProgressDialog(getActivity());
            progressDialog.setMessage("Please Wait...");
            progressDialog.setCancelable(false);
            progressDialog.show();
            super.onPreExecute();
        }

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

            // Retrieve JSON Objects from the given URL address

            jsonobject = JSONFunctions
                    .getJSONfromURL("http://example.com/test/get_category.php?id=16");
            System.out.println("!!!!!!!!!jsonobject===="
                    + jsonobject);
            if (jsonobject != null) {
                try {
                    // Locate the array name in JSON

                    for (int i = 0; i < jsonarray.length(); i++) {
                        HashMap<String, String> hashMap = new HashMap<String, String>();
                        jsonobject = jsonarray.getJSONObject(i);
                        // Retrive JSON Objects
                        hashMap.put("status", jsonobject.getString("status"));
                        hashMap.put("ID", jsonobject.getString("ID"));
                        hashMap.put("category",
                                jsonobject.getString("category"));
                    }
                } catch (JSONException e) {
                    Log.e("Error", e.getMessage());
                    e.printStackTrace();
                }
            } else {

            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            if (progressDialog.isShowing()) {
                progressDialog.dismiss();
            }
        }
    }

    /** Initialize Widgets */
    private void initializeWidgets(View rootView) {

        /** TextView */
        txtTitle = (TextView) rootView.findViewById(R.id.txtTitle);
    }
}
谢谢,
Reena

可能您的系统接受HttpGet请求,因此将
JSONfunctions
类代码更改为

形式

也许对你有帮助

{
data: [
{
status: 1,
ID: "40",
category: "FIRST"
},
{
status: 1,
ID: "41",
category: "SECOND"
}
]
}
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    HttpResponse response = httpclient.execute(httppost);
HttpClient httpclient = new DefaultHttpClient();

           HttpGet request = new HttpGet();
           URI website = new URI(url);
           request.setURI(website);
           HttpResponse response = httpclient.execute(request);