Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在okhttp中使用java发布数组请求_Java_Android_Android Studio_Okhttp - Fatal编程技术网

在okhttp中使用java发布数组请求

在okhttp中使用java发布数组请求,java,android,android-studio,okhttp,Java,Android,Android Studio,Okhttp,我需要使用okhttp java将这样一个数组(从后端开发人员处获得)发送到服务器,有什么想法吗? 最好能找到一些关于它的文献 [answers] => Array ( [0] => Array ( [answer_id] => 4648 [duration_time_question] => 0 [text_open_answe

我需要使用okhttp java将这样一个数组(从后端开发人员处获得)发送到服务器,有什么想法吗? 最好能找到一些关于它的文献

[answers] => Array
    (
        [0] => Array
            (
                [answer_id] => 4648
                [duration_time_question] => 0
                [text_open_answer] => 
            )

        [1] => Array
            (
                [answer_id] => 4650
                [duration_time_question] => 0
                [text_open_answer] => 
            )

        [2] => Array
            (
                [answer_id] => 4667
                [duration_time_question] => 1
                [text_open_answer] => 
            )

        [3] => Array
            (
                [answer_id] => 4652
                [duration_time_question] => 1
                [text_open_answer] => 
            )

        [4] => Array
            (
                [answer_id] => 4678
                [duration_time_question] => 0
                [text_open_answer] => 
            )
我已经尝试了许多变体来发送数组,但都不起作用( 我在需要的部分使用了这段代码

 OkHttpClient client = new OkHttpClient();
            client.newCall(new DoRequest().Post(dictionary, getIntent().getExtras().getString("url"), array))
                    .enqueue(new Callback() {

                        @Override
                        public void onFailure(Call call, IOException e) {
                            e.printStackTrace();
                            System.out.println("Failed");

                        }

                        @Override
                        public void onResponse(Call call, final Response response) throws IOException {
                            String temp = response.body().string();

                            System.out.println("Success " + temp);

                        }


                    });
这是请求支持的类。一方面,当我以键值形式发送数据时,它工作,但另一方面,它不通过for发送数组

public Request Post(Dictionary<String, String> dictionary, String url, Dictionary<String, String> data) {
    RequestBody formBody = null;
    Dictionary<String, String> array = new Hashtable<>();


           for (int i = 0; i < array.size() / 3; i++) {
                formBody = new FormBody.Builder()
                        .add("answers["+i+"]", array.get("answer_id"))
                        .add("answers["+i+"]", array.get("duration_time_question"))
                        .add("answers["+i+"]", array.get("text_open_answer"))
                        .build();
            }


            break;

    }
    return new Request.Builder()
            .url(url)
            .post(formBody).build();
}
公共请求帖子(字典、字符串url、字典数据){
RequestBody-formBody=null;
字典数组=新哈希表();
对于(int i=0;i
所以您希望发送准确的语法,因此json不适用,对吗?这是唯一的字符串吗?只需发送它即可normally@NickCardosoyp,没错,它不是json