我在Android应用中使用Retrofit来处理几个HTTP请求。第一个是获取特定表中的所有信息(这是正常的,并且字段正在被反序列化)。第二种是在同一个表中插入一个新行。当插入表格时,我的所有数据在数据库中显示为空白(我的字符串是""我的整数是0)。当我使用Postman手动插入时,一切都插入正常。我已经检查了我在请求中发送的对象,并且所有数据都已正确填充。
这是我的界面:
public interface FormRequests {
@POST("/createForm.php")
public Call<Response> CreateForm(@Body Form form);
@POST ("/getAllForms.php")
public Call<ArrayList<Form>> GetAllForms();
}
以下是我尝试插入表单的地方:
Retrofit retrofit = new Retrofit.Builder().baseUrl(DatabaseConstants.URL).addConverterFactory(GsonConverterFactory.create()).build();
FormRequests service = retrofit.create(FormRequests.class);
final Call<Response> call = service.CreateForm(form);
new Thread(new Runnable() {
@Override
public void run() {
try {
retrofit.Response<Response> response = call.execute();
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
当我提取所有表数据时,这是插入的JSON:
编辑:这里有关于我的服务器看到的更多信息。我分别使用Postman和我的应用程序时记录了SQL命令:[{&#34; ID&#34;:&#34; 5&#34;&#34;日期&#34;:&#34;&#34;&#34;英里&#34 ;: &#34; 0&#34;&#34;速率&#34;:&#34; 0&#34;&#34; ticket_number_1&#34;:&#34; 0&#34;&#34; QUANTITY_1& #34;:&#34; 0&#34;&#34; lease_number_1&#34;:&#34; 0&#34;&#34; amount_1&#34;:&#34; 0&#34;,& #34; ticket_number_2&#34;:&#34; 0&#34;&#34; QUANTITY_2&#34;:&#34; 0&#34;&#34; lease_number_2&#34;:&#34; 0&# 34;,&#34; amount_2&#34;:&#34; 0&#34;&#34; total_quantity&#34;:&#34; 0&#34;&#34; fuel_percent&#34;:&# 34; 0&#34;&#34; fuel_price&#34;:&#34; 0&#34;&#34; ip_minutes&#34;:&#34; 0&#34;&#34; ip_charge&#34 ;:&#34; 0&#34;&#34; lp_minutes&#34;:&#34; 0&#34;&#34; lp_charge&#34;:&#34; 0&#34;&#34 ; other_fees_1&#34;:&#34; 0&#34;&#34; other_fees_reason_1&#34;:&#34;&#34;&#34; other_fees_2&#34;:&#34; 0&#34; &#34; other_fees_reason_2&#34;:&#34;&#34;&#34;备注&#34;:&#34;&#34;&#34; ip_wait_reason&#34;:&#34; #&34;,&#34; lp_wait_reason&#34;:&#34;&#34;&#34;公司&#34;:&#34;&#34;&#34;驱动&#34 ;: &#34;&#34;&#34;卡车&#34;:&#34;&#34;&#34;拖车&#34;:&#34;&#34;}]
INSERT INTO`database``forms`(`date`,`miles`,`rate`,`ticket_number_1`,`quantity_1`,`lease_number_1`,`amount_1`, `ticket_number_2`,`quantity_2`,`lease_number_2`,`amount_2`,`total_quantity`,`fuel_percent`,`fuel_price`,`ip_minutes`,`ip_charge`,`lp_minutes`, `lp_charge`,`other_fees_1`,`other_fees_reason_1`,`other_fees_2`,`other_fees_reason_2`,`remarks`,`ip_wait_reason`,`lp_wait_reason`, `company`,`driver`,`truck`,`trailer`)VALUES(&#39; 11/13/2015&#39;,&#39; 500&#39;,&#39; 1.16&#39;, &#39; 2342424&#39;,&#39; 12.50&#39;,&#39; 211422&#39;,&#39; 10.50&#39;,&#39; 90897&#39;,&#39 ; 29.50&#39;,&#39; 249023&#39;, &#39; 49.20&#39;,&#39; 23483.60&#39;,&#39; 24.12&#39;,&#39; 2023.23&#39;,&#39; 23&#39;,& #39; 23.3&#39;,&#39; 39&#39;,&#39; 29.5&#39;,&#39; 65.3&#39;,&#39;坦克拒绝&#39;,&# 39; 98.90&#39;,&#39; Rough Road&#39;,&#39;这是我的评论,它很棒&#39;, &#39;坦克被拒绝了,&#39;坦克没有被拒绝&#39;,&#39; Windy Truck LLC&#39; Al Johnson&#39;,&#39; 227 ROF&#39;,&#39; T02&#39;);
INSERT INTO`database``forms`(`date`,`miles`,`rate`,`ticket_number_1`,`quantity_1`,`lease_number_1`,`amount_1`, `ticket_number_2`,`quantity_2`,`lease_number_2`,`amount_2`,`total_quantity`,`fuel_percent`,`fuel_price`,`ip_minutes`,`ip_charge`,`lp_minutes`, `lp_charge`,`other_fees_1`,`other_fees_reason_1`,`other_fees_2`,`other_fees_reason_2`,`remarks`,`ip_wait_reason`,`lp_wait_reason`, `company`,`driver`,`truck`,`trailer`)VALUES(&#39;&#39;&#39;&#39;,&#39;&#39;,&#39;& #39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,& #39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&# 39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&# 39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39;,&#39;&#39 ;,&#39;&#39;,&#39;&#39;,&#39;&#39;);
我也只是通过GSON运行我的表单,看它是否可以转换为JSON,这就是我得到的:
{&#34; amount_1&#34;:&#34; 15.16&#34;&#34; amount_2&#34;:&#34; 12.33&#34;&#34;公司&#34; :&#34; Windy Truck LLC&#34;,&#34; date&#34;:&#34; 11/14/2015&#34;,&#34; driver&#34;:&#34; Al Johnson&# 34;,&#34; fuel_percent&#34;:&#34; 23&#34;&#34; fuel_price&#34;:&#34; 234.00&#34;&#34; ip_charge&#34;:& #34; 245.00&#34;,&#34; ip_minutes&#34;:&#34; 270&#34;,&#34; ip_wait_reason&#34;:&#34;这是等待的原因&#34;,& #34; lease_number_1&#34;:&#34; 100&#34;&#34; lease_number_2&#34;:&#34; 1234123&#34;&#34; lp_charge&#34;:&#34; 332.50& #34;,&#34; lp_minutes&#34;:&#34; 345&#34;,&#34; lp_wait_reason&#34;:&#34;这是另一个等待原因&#34;,&#34;里程&# 34;:&#34; 200&#34;&#34; other_fees_1&#34;:&#34; 343.00&#34;&#34; other_fees_2&#34;:&#34; 233.00&#34 ;, &#34; other_fees_reason_1&#34;:&#34; Rough Road&#34;,&#34; other_fees_reason_2&#34;:&#34; Split Load&#34;,&#34; quantity_1&#34;:&#34 ; 65.16&#34;&#34; QUANTITY_2&#34;:&#34; 890.16&#34;&#34;速率&#34;:&#34; 5.53&#34;&#34;备注& #34;:&#34;这是一个评论&#34;,&#34; ticket_number_1&#34;: #&34; 50&#34;&#34; ticket_number_2&#34;:&#34; 16549&#34;&#34; total_quantity&#34;:&#34; 2,342.64&#34;&#34;预告片&#34;:&#34; 03&#34;,&#34;卡车&#34;:&#34; 227 ROF&#34;}
那里的一切看起来都不错,但看起来Retrofit并没有创造出合适的GSON对象,但我不确定是否会发生这种情况。
我搜索了Google / stackoverflow,但无法找到与此相关的任何内容。任何建议都会很棒,因为我不太了解如何对Retrofit进行故障排除。