2017-08-02 127 views
1

我想通过一个arraylist到PHP做一些操作。当我测试与邮递员我得到以下resoponse ..

{“correct_answers”:“2”,“total_question”:“5”,“消息”:“太棒了!你需要得分至少60%标记的移动一个新的水平。“” message_percentage“:” 40" ,‘saved_message’:‘成功’}

enter image description here

但是,当我尝试发送请求我收到此错误。 。

java.lang.IllegalStateException:预期的BEGIN_OBJECT,但是在第1行第1列处有STRING $

这是我的API接口

@POST( “questions.php”)

@FormUrlEncoded 

Call<QuestionResult> correctQuestionData(@Field("tag") String tag, @Field("str_question_answer[]") ArrayList<QuestionAnswers> str_question_answer, 
             @Field("student_id") String student_id, @Field("level") String level); 
+1

请出示 “QuestionResult” 级。我认为你犯了错误。 –

回答

1

问题是GSON期待的对象,但接收字符串,这是因为JSON的格式可能是错误的。 JSON必须以

{ 

请检查JSON格式。

编辑: 查看您的查询的参数,我认为你要发送的,而不是你把在邮递员什么服务器用一个String响应一个JSON而不是其他参数

+0

{“correct_answers”:“2”,“total_question”:“5”,“message”:“好极了,你需要至少60%的分数才能移动到下一关。”,“message_percentage”:“40 “,”saved_message“:”success“} 这是我用邮差测试时收到的格式。 –

+0

回波json_encode([ “correct_answers”=>计数($ correct_answers)。 “”, “total_question”=> $ total_question。 “”, “消息”=> $结果[ “消息”], “message_percentage” => $ percent。“”, “message”=> $ results [“message”], “saved_message”=> $ results [“saved_message”] ]); 这就是我在php代码中定义的内容 –

+0

当您获取数据时,尝试复制并粘贴浏览器的结果,或者在reotrofit2中的“onFailure”中设置一个中断点以获取答案。可能是你正在发送一个错误的参数,并不是相同的答案 –

0

我想你在QuestionResult类中犯了错误。它的格式应该是这样

public class QuestionResult{ 

public String correct_answers; 
public String total_question; 
public String message; 
public String message_percentage; 
public String saved_message;  

}

相关问题