jsonexception value <br of =“”type =“”java.lang.string =“”can =“”be =“”converted =“”to =“”“jsonarray =”“

时间:2017-09-21 07:49:26

标签: android arrays android-volley

1 个答案:

答案 0 :(得分:0)

将params发送到服务器

Map<String, String> params = new HashMap<String, String>();

 try {
        params.put("user_id", user_id);
        JSONObject JsonObj = new JSONObject(params);
        JsonArrayRequest jar=new JsonArrayRequest
        (Request.Method.POST,
                Constants.MyPOST_URL  ,
                JsonObj,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        try{
                             getData_and_set_Model(response);
                        }catch (Exception ex){
                            ex.printStackTrace();
                        }
                    }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                    Toast.makeText(productActivity.this,"VolleyError : " + 
                    error.getMessage()+ "", Toast.LENGTH_SHORT).show();                    
            }
        });
        AppController.getInstance().addToRequestQueue(jsonObjectReq);
    }catch (Exception ex){}

create class AppController  extends Application 
AndroidManifest中的

&gt;

> <application
>         android:name=".AppController"
> 
> <uses-permission android:name="android.permission.INTERNET" />
public class AppController extends Application {

    public static final String TAG = AppController.class.getSimpleName();
    private RequestQueue mRequestQueue;
    private ImageLoader mImageLoader;

    private static AppController mInstance;
    @Override
    public void onCreate() {
        super.onCreate();
        mInstance = this;       
    }

    public static synchronized AppController getInstance() {
        return mInstance;
    }
    public RequestQueue getRequestQueue() {
        if (mRequestQueue == null) {
            mRequestQueue = Volley.newRequestQueue(getApplicationContext());
        }
        return mRequestQueue;
    }

    public ImageLoader getImageLoader() {
        getRequestQueue();
        if (mImageLoader == null) {
            mImageLoader = new ImageLoader(this.mRequestQueue,
                    new LruBitmapCache());
        }
        return this.mImageLoader;
    }

    public <T> void addToRequestQueue(Request<T> req, String tag) {
        // set the default tag if tag is empty
        req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
        getRequestQueue().add(req);
    }

    public <T> void addToRequestQueue(Request<T> req) {
        req.setTag(TAG);
        getRequestQueue().add(req);
    }

    public void cancelPendingRequests(Object tag) {
        if (mRequestQueue != null) {
            mRequestQueue.cancelAll(tag);
        }
    }
}

你的问题是发送服务器

告诉我是否解决了