应为 BEGIN_OBJECT 但在第 3 行第 1 列路径 $ 处为 STRING

Expected BEGIN_OBJECT but was STRING at line 3 column 1 path $

我正在尝试通过改造将字符串类型列表发送到 mysql 数据库。当我尝试使用邮递员时,我获得了成功,但我收到来自 android studio.

的错误消息

我的API界面:

@FormUrlEncoded
@POST("yesilegeservices/insertJob.php")
fun insertJob  (@Field("Token")         token:String, 
                @Field("StartingDate")  StartingDate:String, 
                @Field("TargetTime")    TargetTime:String,
                @Field("JobContent")    JobContent:String,
                @Field("StaffList[]")   StaffList:List<String>,  // My List
                @Field("ReleaseDate")   ReleaseDate:String, 
                @Field("KindId")        kindId:String):Single<JobInsertResponse>

我的数据 Class 响应:

data class JobInsertResponse(
@SerializedName("job") @Expose val incomingId:List<singleUuid>,
@SerializedName("jobInsertSuccess") val success:Int
)

data class singleUuid (
@SerializedName("JobId") @Expose val uuid:Int
)

Php 回复:

{"job":[{"JobId":"15"}],"jobInsertSuccess":1}

Android 工作室错误信息:

java.lang.IllegalStateException: Expected BEGIN_OBJECT but was 
STRING at line 3 
column 1 path $

OkHttp 日志:

2021-07-02 15:49:31.350 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: --> POST 

http://10.0.2.2:8888/yesilegeservices/insertJob.php
2021-07-02 15:49:31.350 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: Content-Type: application/x-www-form- 
urlencoded

2021-07-02 15:49:31.351 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: Content-Length: 211

2021-07-02 15:49:31.352 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: 
Token=yN4XGdFIzIMOrgE3Q4rB1jqoNJUbpfOqHI3IuuiUU&StartingDate=02- 
07- 
2021&TargetTime=15.49&JobContent=lorem%20impsun%20dolor&
StaffList%5B%5D=10&StaffList%5B%5D=11&StaffList%5B%5D=12
&ReleaseDate=02-07-2021&KindId=1

2021-07-02 15:49:31.352 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: --> END POST (211-byte body)
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: <-- 200 OK 

http://10.0.2.2:8888/yesilegeservices/insertJob.php (28ms)
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: Date: Fri, 02 Jul 2021 12:49:39 GMT

2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: Server: Apache/2.4.46 (Unix) 
OpenSSL/1.0.2u PHP/8.0.0 mod_wsgi/3.5 Python/2.7.13 
mod_fastcgi/mod_fastcgi-SNAP-0910052141 mod_perl/2.0.11 

Perl/v5.30.1
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: X-Powered-By: PHP/8.0.0
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: Content-Length: 98
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: Keep-Alive: timeout=5, max=100
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: Connection: Keep-Alive

2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: Content-Type: text/html; charset=UTF-8
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient:                 
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient:             
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: Incorrect date value: '02-07-2021' for 
column 'ReleaseDate' at row 1
2021-07-02 15:49:31.381 16777-16916/com.thic.yesilege 
I/okhttp.OkHttpClient: <-- END HTTP (98-byte body)   

我认为问题出在我发布的列表中,因为如果我删除列表,结果是成功的。

怎么了?

我认为问题出在你的数据中 class.Your jobs arraylist containts objects 和 inside objects 有一串 jobId 但你将它解析为整数。

试试这个解决方案可能会有帮助。

data class JobInsertResponse(
        @SerializedName("job") @Expose val incomingId:List<singleUuid>,
        @SerializedName("jobInsertSuccess") val success:Int
    )

    data class singleUuid (
        @SerializedName("JobId") @Expose val uuid:String
    )

日期有问题。 Mysql 数据库接受日期格式 = "yyyy-MM-dd" 但我的日期格式为 "dd-MM-yyyy"。