Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.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
Can';t将JSON转换为对象_Json_Kotlin_Gson - Fatal编程技术网

Can';t将JSON转换为对象

Can';t将JSON转换为对象,json,kotlin,gson,Json,Kotlin,Gson,Json响应如下所示: { “地位”:1, “数据”:[ [ { “id”:“4iQDR9r1Ch”, “正文”:“测试”, “da”:“1601575850”, “dm”:“1601575850” } ] ] } 我的班级: 数据类注释响应( @SerializedName(“状态”)val状态:Int, @SerializedName(“数据”)val数据:列表) 数据类NoteResponse( @SerializedName(“id”)val id:字符串, @SerializedNa

Json响应如下所示:

{
“地位”:1,
“数据”:[
[
{
“id”:“4iQDR9r1Ch”,
“正文”:“测试”,
“da”:“1601575850”,
“dm”:“1601575850”
}
]
]
}
我的班级:

数据类注释响应(
@SerializedName(“状态”)val状态:Int,
@SerializedName(“数据”)val数据:列表)
数据类NoteResponse(
@SerializedName(“id”)val id:字符串,
@SerializedName(“正文”)val正文:字符串,
@SerializedName(“da”)val da:String,
@SerializedName(“dm”)val dm:String
)
错误消息:
com.google.gson.stream.MalformedJsonException:第1行第48列的未终止对象路径$.data[0][0]。正文


怎么了?JSON是有效的,并且已检查类的正确性

如果您有权访问
Gson
类,请尝试以下操作。
lenient
模式可能允许您查看它是否有效,以及非
lenient
模式无法解析的字符

Gson gson = new Gson();
JsonReader reader = new JsonReader(new StringReader(<insert response>));
reader.setLenient(true);
Gson-Gson=new-Gson();
JsonReader=newJSONReader(newStringReader());
读者:setLenient(真);

您是否有权访问
Gson
类,例如
Gson Gson=new Gson()
?@RossSheppard是的,其他转换(使用另一个json和类型)工作得很好您是否尝试将
Gson
置于
lenient
模式?这可能有助于查看响应中是否有
Gson
不喜欢的字符。我添加了一个答案,但如果不起作用,请告诉我!我刚刚使用了它,它起了作用,你确定你得到的JSON是这样的吗?