gpt4 book ai didi

android - 我的错误 : Use JsonReader. setLenient(true) 在第 1 行第 1 列路径 $ 处接受格式错误的 JSON

转载 作者:行者123 更新时间:2023-11-29 01:04:25 26 4
gpt4 key购买 nike

我正在从 api 结构中获取数据并出现此错误。我检查了很多网站以供引用,但我没有找到合适的解决方案

public class ApiClient {

public static final String BASE_URL = "http://stock.adverscribe.in/api/controllers/";
private static Retrofit retrofit = null;
public
static Retrofit getClient() {

Gson gson = new GsonBuilder()
.setLenient()
.create();
if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
}
return retrofit;
}
}

接口(interface)接口(interface).java

public interface ApiInterface {

@GET("getMenu")
Call<MenuResponse> getMenuResult();
}

主 Activity .java

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);
Call<MenuResponse> call = apiService.getMenuResult();
call.enqueue(new Callback<MenuResponse>() {
@Override
public void onResponse(Call<MenuResponse> call, Response<MenuResponse> response) {
int code = response.body().getCode();
Toast.makeText(MainActivity.this, "" + code, Toast.LENGTH_SHORT).show();
}

@Override
public void onFailure(Call<MenuResponse> call, Throwable t) {
Toast.makeText(MainActivity.this, "" + t.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}

这是json数据

{
"code": 200,
"message": "SUCCESS",
"data": {
"menu": [
{
"division": {
"stock_division_id": "1",
"stock_division_name": "Men",
"stock_division_status": "1",
"created_date": "2018-01-12 11:59:00",
"updated_date": "2018-01-12 11:59:22"
},
"cat": [
{
"stock_category_id": "1",
"stock_division_id": "1",
"stock_category_name": "T-Shirts",
"stock_category_status": "1",
"created_date": "2018-01-12 12:00:14",
"updated_date": "2018-01-12 12:00:14"
}
]
},
{
"division": {
"stock_division_id": "2",
"stock_division_name": "Women",
"stock_division_status": "1",
"created_date": "2018-01-12 11:59:44",
"updated_date": "2018-01-12 11:59:44"
},
"cat": [
{
"stock_category_id": "2",
"stock_division_id": "2",
"stock_category_name": "T-Shirts",
"stock_category_status": "1",
"created_date": "2018-01-12 12:02:24",
"updated_date": "2018-01-12 12:02:24"
}
]
}
]
}
}

错误栈

 01-23 18:34:14.219 13628-13628/? I/art: Late-enabling -Xcheck:jni
01-23 18:34:14.544 13628-13628/com.adverscribe.myapplication W/System: ClassLoader referenced unknown path: /data/app/com.adverscribe.myapplication-2/lib/arm
01-23 18:34:14.567 13628-13628/com.adverscribe.myapplication I/InstantRun: starting instant run server: is main process
01-23 18:34:14.687 13628-13628/com.adverscribe.myapplication W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
01-23 18:34:14.998 13628-13628/com.adverscribe.myapplication D/NetworkSecurityConfig: No Network Security Config specified, using platform default
01-23 18:34:15.123 13628-13650/com.adverscribe.myapplication I/Adreno: QUALCOMM build : ead2395, I23cc4685e6
Build Date : 04/11/17
OpenGL ES Shader Compiler Version: XE031.09.00.04
Local Branch :
Remote Branch : quic/gfx-adreno.lnx.1.0.r5-rel
Remote Branch : NONE
Reconstruct Branch : NOTHING
01-23 18:34:15.137 13628-13650/com.adverscribe.myapplication I/OpenGLRenderer: Initialized EGL, version 1.4
01-23 18:34:15.137 13628-13650/com.adverscribe.myapplication D/OpenGLRenderer: Swap behavior 1
01-23 18:34:15.170 13628-13628/com.adverscribe.myapplication W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
01-23 18:34:15.205 13628-13628/com.adverscribe.myapplication I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@ca6d04c time:134394442
01-23 18:34:16.628 13628-13628/com.adverscribe.myapplication I/ViewRootImpl: ViewRoot's KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=134395859, downTime=134395859, deviceId=-1, source=0x101 } to DecorView@67df74[MainActivity]
01-23 18:34:16.630 13628-13628/com.adverscribe.myapplication I/AudioManagerEx: AudioManagerEx created
01-23 18:34:16.709 13628-13628/com.adverscribe.myapplication I/ViewRootImpl: ViewRoot's KeyEvent { action=ACTION_UP, keyCode=KEYCODE_BACK, scanCode=0, metaState=0, flags=0x48, repeatCount=0, eventTime=134395942, downTime=134395859, deviceId=-1, source=0x101 } to DecorView@67df74[MainActivity]

最佳答案

您的 api 没有返回有效的 JSON

stdClass Object([stock_division_id] => 1[stock_division_name] => Men[stock_division_status] => 1[created_date] => 2018 - 01 - 12 11: 59: 00[updated_date] => 2018 - 01 - 12 11: 59: 22) stdClass Object([stock_division_id] => 2[stock_division_name] => Women[stock_division_status] => 1[created_date] => 2018 - 01 - 12 11: 59: 44[updated_date] => 2018 - 01 - 12 11: 59: 44) {
"code": 200,
"message": "SUCCESS",
"data": {
"menu": [{
"division": {
"stock_division_id": "1",
"stock_division_name": "Men",
"stock_division_status": "1",
"created_date": "2018-01-12 11:59:00",
"updated_date": "2018-01-12 11:59:22"
},
"cat": [{
"stock_category_id": "1",
"stock_division_id": "1",
"stock_category_name": "T-Shirts",
"stock_category_status": "1",
"created_date": "2018-01-12 12:00:14",
"updated_date": "2018-01-12 12:00:14"
}]
}, {
"division": {
"stock_division_id": "2",
"stock_division_name": "Women",
"stock_division_status": "1",
"created_date": "2018-01-12 11:59:44",
"updated_date": "2018-01-12 11:59:44"
},
"cat": [{
"stock_category_id": "2",
"stock_division_id": "2",
"stock_category_name": "T-Shirts",
"stock_category_status": "1",
"created_date": "2018-01-12 12:02:24",
"updated_date": "2018-01-12 12:02:24"
}]
}]
}
}

关于android - 我的错误 : Use JsonReader. setLenient(true) 在第 1 行第 1 列路径 $ 处接受格式错误的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48402127/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com