通过使用Retrofit库来使用服务,我已经为我的接口、模型以及如何使用接口添加了代码。
我不断得到一个GSON抛出“Expected BEGIN_OBJECT but but BEGIN_ARRAY”
接口
@GET("api/RetrofitAndroidArrayResponse")
Call<student> getStudentDetails();
模范公开课学生{
//Variables that are in our json
private int StudentId;
private String StudentNa
我使用Retrofit 2,在上使用测试JSON,.It是非常简单的JSON。我为什么要接受这个错误?
在实际项目中,我也有这个错误,但我认为,这是因为我有非常大的JSON。我使用你的测试JSON。(需要帮助)
java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $
这是JSON
{ "ip":"54.196.188.78“}
My Interface
public interface UmoriliApi {
@GE
尝试使用Retrofit以JSON格式发送信息,但它进入Retrofit的onFailure方法并引发以下错误:
com.google.gson.stream.MalformedJsonException: Use JsonReader.setLenient(true) to accept malformed JSON at line 1 column 1 path $
到目前为止,我已经尝试使用以下链接的答案来解决这个问题: 1) 2)
这是我的代码:
改装接口:
public interface ServerApi {
@POST("/register/test"
我正在通过类似于此的API获得一个JSON。
如您所见,第一个对象名是增量值。如何使用moshi处理数据类或接口中的变量对象名?对于“正常”的JSON文件,这段代码正在工作。是否有一种方法使数据类对象名变量,或者如何更改接口以创建常量名称?
数据类别:
data class PhilipsHueLightsApi(
val lightId: List<HueLight>
)
data class HueLight(
val state: HueLightState,
val swupdate: HueLightSwupdate,
val
使用Retrofit在activity中显示服务器JSON数据。通过gson转换JSON数据。 给出错误:"java.lang.IllegalStateException:预期的BEGIN_ARRAY,但在第1行第2列的路径$“中出现BEGIN_OBJECT JSON格式: {"success":1,"company":[{"Cmp_Id":"1","Cmp_Name":"ABC","GSTIN":"AAAA"}]} 代码: class Company {
我是API世界的新手。在尝试使用Retrofit和Moshi获取API时,我似乎得到了0的结果,而我不应该这样做。有人能告诉我我做错了什么吗?
编辑:在进一步的研究中,我实际上在视图模型中得到了这个错误,我在该模型中调用API:
Expected BEGIN_ARRAY but was BEGIN_OBJECT at path $
我试图获取的API:
https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=2021-01-01&endtime=2021-08-24&minmag
我有一个用Kotlin编写的Android应用程序,它从API获取数据,现在它只是一个本地托管的JSON文件。当我试图获取数据时,我收到了一个错误,我的列表persons没有初始化,因此persons == null并且没有接收到数据。我不确定我做错了什么,也不知道如何解决这个问题。 模型 data class Person (
@Json(name = "personId")
val personId: Int,
@Json(name = "personName")
val name: String,
@Json(name =
我想从JSON中获取一些数据,但是gson给出了一个错误。我想知道怎样才能解决这个问题?
我使用的是dagger2(这个部分是100%确定和工作的)和rxJava(这个部分总是调用onError方法)。
My模型:
@Data
@NoArgsConstructor
public class GradeModel {
//I'm using lombok to generate getters and setters.
@SerializedName("grade")
@Expose
private DecimalFormat grades;
我如何使用retrofit来解析它呢?我收到错误BEGIN_OBJECT but was BEGIN_ARRAY
现在,我这样解析它..
下面是适配器类
public static RetroInterface getCommonPathInterface() {
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("myurl")
.build();
records= restAdapter.creat
我是一个非常新的翻新。我想从server.but获取一些数据,但我无法做到这一点。请帮助me.when我调用api,然后显示一个错误“期望的开始数组,但被开始对象”。
private void getCatagories(){
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.addConverterFactory(GsonConverterFactory.create()) //Here we are using the GsonConverterFa
我试着用Retrofit获得一些数据,并且我得到了这个错误。我明白什么是错误,但我不知道如何修复它:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2 path $
我试过在其他问题上找到答案,但我找不到任何类似我的问题.
我的界面代码:
public interface ApiInterface {
@GET("api/category")
Call&
我想通过使用retrofit来获取网络连接状态。 我使用CoroutineExceptionHandler来显示Toast,但它会得到Can't toast on a thread that has not called Looper.prepare()。 如果我不使用CoroutineExceptionHandler,当网络没有连接时,它会崩溃并获得FATAL EXCEPTION: DefaultDispatcher-worker-1。 如何获取网络未连接和连接超时状态? 这是我的代码,谢谢! object APIClientManager {
var tag: Strin
我的服务器为所有请求返回一个基本的JSON结构,如:
{
"success": false,
"data": {
"errors": {
"email": [
"This is not an email."
],
"password": [
"The password must be at least 6