Java 想要在微调器中将Json数据与文本和图像绑定

Java 想要在微调器中将Json数据与文本和图像绑定,java,android,json,jsonp,Java,Android,Json,Jsonp,我可以正确地获取文本数据,没有任何问题,但我不知道如何从Json数据中获取图像。所以拜托,我想有人改变我的密码。我试过了,但没能成功 //Json数据 **'c'([{"categoryId":1,"categoryName":"Theater","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":2,"categoryName":"Mall","imagePath":"ht

我可以正确地获取文本数据,没有任何问题,但我不知道如何从Json数据中获取图像。所以拜托,我想有人改变我的密码。我试过了,但没能成功

//Json数据

 **'c'([{"categoryId":1,"categoryName":"Theater","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":2,"categoryName":"Mall","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":3,"categoryName":"Hospital","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":4,"categoryName":"School","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":5,"categoryName":"College","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":6,"categoryName":"ChemistShop","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"}]);*
public class SpinnerJsonFetch extends ActionBarActivity {

Spinner sp ;

TextView categoryId;

TextView CategoryName;

ArrayList<String> oslist = new ArrayList<String>();

//JSON Node Names 
private static final String TAG_OS = "c";
private static final String TAG_ID = "categoryId";
private static final String TAG_NAME = "categoryName";


@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_spinner_json_fetch);

    sp = (Spinner)findViewById(R.id.spList);
    //for checking internet connection 
    ConnectionDetector cd = new ConnectionDetector(getApplicationContext());

    if (!cd.isConnectingToInternet()) {

        Toast.makeText(getApplicationContext(), "Please check your internet      connection", Toast.LENGTH_LONG).show();
    }
    else
             //calling GetAsync class 
    new GetAsync().execute();

}
    //GetAsync class for operations 
private class GetAsync extends AsyncTask<String, String, JSONObject> {

    private ProgressDialog pDialog;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        pDialog = new ProgressDialog(SpinnerJsonFetch.this);

        pDialog.setMessage("Getting Data ...");

        pDialog.setIndeterminate(false);

        pDialog.setCancelable(true);

        pDialog.show();

    }

    @Override
    protected JSONObject doInBackground(String... args) {

        JSONParser jParser = new JSONParser();

        // Getting JSON from URL
        JSONObject json = jParser.getJSONFromUrl(Tags.url);

        System.out.println("Hello");

        return json;
    }

    //on post execute
    @Override
    protected void onPostExecute(JSONObject json) {

        pDialog.dismiss();

        try {

            // Getting Array of Contacts
            JSONArray jsonArray = json.getJSONArray(TAG_OS);

            final String[] items = new String[jsonArray.length()]; 


            // looping through All Contacts
            for(int i = 0; i < jsonArray.length(); i++){

                JSONObject c = jsonArray.getJSONObject(i);

                // Storing each json item in variable
                String name = c.getString(TAG_NAME);

                String id = c.getString(TAG_ID);

                items[i] = name ;


                System.out.println("Hello events "+items);

            }
                    //array adapter to store the items 
            ArrayAdapter<String> adapter = 
                new ArrayAdapter<String> (SpinnerJsonFetch.this, android.R.layout.simple_spinner_item, items);       
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            sp.setAdapter(adapter);

        } catch (JSONException e) {

            e.printStackTrace();

        }

    }       

}    

}
//这是我的主要活动

 **'c'([{"categoryId":1,"categoryName":"Theater","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":2,"categoryName":"Mall","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":3,"categoryName":"Hospital","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":4,"categoryName":"School","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":5,"categoryName":"College","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"},{"categoryId":6,"categoryName":"ChemistShop","imagePath":"http://locator.antheminfotech.net/images/icons/minus.png"}]);*
public class SpinnerJsonFetch extends ActionBarActivity {

Spinner sp ;

TextView categoryId;

TextView CategoryName;

ArrayList<String> oslist = new ArrayList<String>();

//JSON Node Names 
private static final String TAG_OS = "c";
private static final String TAG_ID = "categoryId";
private static final String TAG_NAME = "categoryName";


@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_spinner_json_fetch);

    sp = (Spinner)findViewById(R.id.spList);
    //for checking internet connection 
    ConnectionDetector cd = new ConnectionDetector(getApplicationContext());

    if (!cd.isConnectingToInternet()) {

        Toast.makeText(getApplicationContext(), "Please check your internet      connection", Toast.LENGTH_LONG).show();
    }
    else
             //calling GetAsync class 
    new GetAsync().execute();

}
    //GetAsync class for operations 
private class GetAsync extends AsyncTask<String, String, JSONObject> {

    private ProgressDialog pDialog;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

        pDialog = new ProgressDialog(SpinnerJsonFetch.this);

        pDialog.setMessage("Getting Data ...");

        pDialog.setIndeterminate(false);

        pDialog.setCancelable(true);

        pDialog.show();

    }

    @Override
    protected JSONObject doInBackground(String... args) {

        JSONParser jParser = new JSONParser();

        // Getting JSON from URL
        JSONObject json = jParser.getJSONFromUrl(Tags.url);

        System.out.println("Hello");

        return json;
    }

    //on post execute
    @Override
    protected void onPostExecute(JSONObject json) {

        pDialog.dismiss();

        try {

            // Getting Array of Contacts
            JSONArray jsonArray = json.getJSONArray(TAG_OS);

            final String[] items = new String[jsonArray.length()]; 


            // looping through All Contacts
            for(int i = 0; i < jsonArray.length(); i++){

                JSONObject c = jsonArray.getJSONObject(i);

                // Storing each json item in variable
                String name = c.getString(TAG_NAME);

                String id = c.getString(TAG_ID);

                items[i] = name ;


                System.out.println("Hello events "+items);

            }
                    //array adapter to store the items 
            ArrayAdapter<String> adapter = 
                new ArrayAdapter<String> (SpinnerJsonFetch.this, android.R.layout.simple_spinner_item, items);       
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            sp.setAdapter(adapter);

        } catch (JSONException e) {

            e.printStackTrace();

        }

    }       

}    

}

json中没有图像。只有指向web上图像的url。如果您可以提取文本,那么您也可以提取此url。您没有在
我的JSONParsor文件中显示代码的使用位置。我有单独的jsonparser文件。。你想从jsonparser中得到什么样的代码..请重读我写的。你的话和问题没有道理。