当多个带空格的单词通过url发送到Json进行android解析时,Json响应为null

当多个带空格的单词通过url发送到Json进行android解析时,Json响应为null,android,json,Android,Json,我想给我的图像添加注释,当我给一个单词添加注释时,它使用asyntask成功保存,但当我发送类似“asas sas asas asas asas asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa。 请给我一些建议 我的密码是 package com.asyntask; import

我想给我的图像添加注释,当我给一个单词添加注释时,它使用asyntask成功保存,但当我发送类似“asas sas asas asas asas asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa asa。 请给我一些建议

我的密码是

package com.asyntask;

import java.util.ArrayList;
import java.util.concurrent.TimeoutException;

import org.json.JSONException;
import org.json.JSONObject;

import com.model_classes.Model_Image_list;
import com.model_classes.Model_User_info;
import com.model_classes.Model_Video_list;
import com.utility.BaseUrl;
import com.utility.ConnectionDetector;
import com.utility.CustomDialogue;
import com.utility.JSONfunctions;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.res.Resources.NotFoundException;
import android.os.AsyncTask;

//DownloadJSON AsyncTask
public  class CommentListAsynTask extends AsyncTask<String, String, JSONObject>
{ 
    int flag=0;
    String userID,video_title,type;
    Model_Image_list image_list_info;
    Model_Video_list video_list_info;
    ProgressDialog mProgressDialog;
    Context context;
    ArrayList<Model_Video_list> arraylist_video_list=new ArrayList<Model_Video_list>();
    ArrayList<Model_Image_list> arraylist_image_list;
    ArrayList<Model_User_info> arraylist_user_info;
    JSONObject jsonobjectResult;
    String str_status,action,viewId,comment;
    public CommentListAsynTask(Context context) 
    {
        this.context=context;
    }

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


                mProgressDialog = new ProgressDialog(context);
                mProgressDialog.setMessage("Please wait...");
                mProgressDialog.setCancelable(false);
        arraylist_image_list = new ArrayList<Model_Image_list>();

        mProgressDialog.show();

    }


    protected JSONObject doInBackground(String... arg)

    {
        this.userID=arg[0];
        System.out.println(userID+".......UserID");
        this.viewId=arg[1];
        System.out.println(viewId+".......viewID");
        this.comment=arg[2];
        System.out.println(comment+".......Comments");
        this.action=arg[3];
        System.out.println(action+".......actionID");

        // Create an array
        arraylist_user_info = new ArrayList<Model_User_info>();


        //Send URL to JSONfunction class in which parsing the JSON data.
        try 
        {
            jsonobjectResult = JSONfunctions.getJSONfromURL(BaseUrl.URL+"commentImageVideo.php?userIdForComment="
                    +userID+"&viewIdForComment="+viewId+"&comment="+comment+"&actionComment="+action);
            System.out.println(jsonobjectResult+"................Result");

            // Locate the array name in JSON
            if(jsonobjectResult !=null)
            {   if(jsonobjectResult.has("error"))
            {
                flag=1;
            }
            if(jsonobjectResult.has("null"))
            {
                flag=1;
            }
            if(jsonobjectResult.has(""))
            {
                flag=1;

            }
            else
            {       
                str_status=jsonobjectResult.getString("status");
                System.out.println(str_status+"..........>Ststus");
            }
            }


        }
        catch (NotFoundException e)
        {
            e.printStackTrace();
        } catch (TimeoutException e) 
        {
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return jsonobjectResult;


    }

    @Override
    protected void onPostExecute(JSONObject response) 
    {  
            mProgressDialog.dismiss();
        if(flag != 1)
        {
            try {
                if(response.getString("status").equalsIgnoreCase("Success."))
                {
                    System.out.println(str_status+".............Comment status");
                    CustomDialogue dialogue=new CustomDialogue(context, "You have successfully Comment");
                    dialogue.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            /*if(str_status.equalsIgnoreCase("Error."))
            {
                CustomDialogue dialogue=new CustomDialogue(context, "You have Already liked");
                dialogue.show();

            }*/
        }
        else
        {
            ConnectionDetector.displaySlowNetworkDialog((Activity)context);
        }

    }
}

虽然不确定这是否能解决您的问题,但在发送getRequest之前,请尝试为您的评论设置%20

comment = comment.replaceAll(" ","%20"); //escape spaces trim() can also be useful
jsonobjectResult = JSONfunctions.getJSONfromURL(BaseUrl.URL+"commentImageVideo.php?userIdForComment="
                +userID+"&viewIdForComment="+viewId+"&comment="+comment+"&actionComment="+action);

在捕获(异常e)中,打印异常。这将有助于理解问题,这可能就是问题所在。但更好的是,改用。谢谢。。。通过使用replace All()解决了这个问题,但不知道Uri.Builder是如何使用的。
comment = comment.replaceAll(" ","%20"); //escape spaces trim() can also be useful
jsonobjectResult = JSONfunctions.getJSONfromURL(BaseUrl.URL+"commentImageVideo.php?userIdForComment="
                +userID+"&viewIdForComment="+viewId+"&comment="+comment+"&actionComment="+action);