Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.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
Android 使用改进的嵌套Json_Android_Json_Nested_Retrofit - Fatal编程技术网

Android 使用改进的嵌套Json

Android 使用改进的嵌套Json,android,json,nested,retrofit,Android,Json,Nested,Retrofit,我想通过改型从json中读取sub_category>id和名称 但下面的代码给出了失败的响应 java.lang.IllegalStateException:应为BEGIN\u对象,但为 从第2行第2列路径开始\u数组$ 我的Json [ { "id": "1", "name": "Invamore", "sub_category": [ { "id": "101", "name": "Banner"

我想通过改型从json中读取sub_category>id和名称

但下面的代码给出了失败的响应

java.lang.IllegalStateException:应为BEGIN\u对象,但为 从第2行第2列路径开始\u数组$

我的Json

[
{
    "id": "1",
    "name": "Invamore",
    "sub_category": [
        {
            "id": "101",
            "name": "Banner"
        },
        {
            "id": "102",
            "name": "3 sided Dangler"
        },
        {
            "id": "103",
            "name": "Leaflet"
        }
    ]
},
{
    "id": "2",
    "name": "HUPS",
    "sub_category": [
        {
            "id": "103",
            "name": "Leaflet"
        },
        {
            "id": "104",
            "name": "Posters"
        },
        {
            "id": "105",
            "name": "Sunpack"
        }
    ]
},
{
    "id": "3",
    "name": "Xplore",
    "sub_category": [
        {
            "id": "101",
            "name": "Banner"
        },
        {
            "id": "103",
            "name": "Leaflet"
        },
        {
            "id": "106",
            "name": "Dangler"
        },
        {
            "id": "107",
            "name": "Vertical Streamer"
        }
    ]
},
{
    "id": "4",
    "name": "Xpress",
    "sub_category": [
        {
            "id": "101",
            "name": "Banner"
        },
        {
            "id": "103",
            "name": "Leaflet"
        },
        {
            "id": "108",
            "name": "Streamer"
        }
    ]
},
{
    "id": "5",
    "name": "Matrix",
    "sub_category": [
        {
            "id": "103",
            "name": "Leaflet"
        }
    ]
},
{
    "id": "6",
    "name": "Instabrite",
    "sub_category": [
        {
            "id": "103",
            "name": "Leaflet"
        }
    ]
},
{
    "id": "7",
    "name": "Mileage",
    "sub_category": [
        {
            "id": "107",
            "name": "Vertical Streamer"
        }
    ]
},
{
    "id": "8",
    "name": "Onam Posm",
    "sub_category": [
        {
            "id": "101",
            "name": "Banner"
        },
        {
            "id": "106",
            "name": "Dangler"
        }
    ]
}]
Backend.java

public void pos_func(String user_id) {

    ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);      

    Call call = apiService.POS_MODEL_CALL(user_id);
    call.enqueue(new Callback() {
        @Override
        public void onResponse(Call call, Response response) {

        }

        @Override
        public void onFailure(Call call, Throwable t) {
            Log.d("sk_log", "Failed! Error = " + t.getMessage());

        }
    });

}
public void pos_func(String user_id) {
        dataArrayList1 = new ArrayList<>();
        ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);


        Call <List<ValuesPos>> call = apiService.POS_MODEL_CALL(user_id);

        call.enqueue(new Callback<List<ValuesPos>>() {
            @Override
            public void onResponse(Call<List<ValuesPos>> call, Response<List<ValuesPos>> response) {
                Log.d("sk_log", "Status POS Code = successsss");
                dataArrayList1 = response.body();

                //ValuesPos valuesPos = (ValuesPos) response.body();
                Log.d("sk_log", "name==="+dataArrayList1.get(0).getName());
                Log.d("sk_log", "name==="+dataArrayList1.get(0).getSubCategory().get(0).getName());
                CustomerCollection.spinner_pos(dataArrayList1);


            }
            @Override
            public void onFailure(Call<List<ValuesPos>> call, Throwable t) {
                Log.d("sk_log", "Failed! Error = " + t.getMessage());               

            }
        });      
    }
ApiInterface.java

 @FormUrlEncoded
@POST("pos_distributed.php")
Call<ValuesPos> POS_MODEL_CALL(@Field("user_id") String user_id);
@FormUrlEncoded
@POST("pos_distributed.php")
Call<List<ValuesPos>> POS_MODEL_CALL(@Field("user_id") String user_id);

Json包含一个
ValuesPos

@FormUrlEncoded
@POST("pos_distributed.php")
Call<List<ValuesPos>> POS_MODEL_CALL(@Field("user_id") String user_id);
apinterface.java调用单个
ValuesPos

@FormUrlEncoded
@POST("pos_distributed.php")
Call<List<ValuesPos>> POS_MODEL_CALL(@Field("user_id") String user_id);

编辑

更改apinterface.java以调用
ValuesPos的列表

@FormUrlEncoded
@POST("pos_distributed.php")
Call<List<ValuesPos>> POS_MODEL_CALL(@Field("user_id") String user_id);
@FormUrlEncoded
@POST(“pos_distributed.php”)
Call POS_MODEL_Call(@Field(“user_id”)字符串user_id);

Json包含一个
值的列表

@FormUrlEncoded
@POST("pos_distributed.php")
Call<List<ValuesPos>> POS_MODEL_CALL(@Field("user_id") String user_id);
apinterface.java调用单个
ValuesPos

@FormUrlEncoded
@POST("pos_distributed.php")
Call<List<ValuesPos>> POS_MODEL_CALL(@Field("user_id") String user_id);

编辑

更改apinterface.java以调用
ValuesPos的列表

@FormUrlEncoded
@POST("pos_distributed.php")
Call<List<ValuesPos>> POS_MODEL_CALL(@Field("user_id") String user_id);
@FormUrlEncoded
@POST(“pos_distributed.php”)
Call POS_MODEL_Call(@Field(“user_id”)字符串user_id);

以下是适用于我的全部代码。。。(谢谢你的帮助)

修正二类

ApiInterface.java

 @FormUrlEncoded
@POST("pos_distributed.php")
Call<ValuesPos> POS_MODEL_CALL(@Field("user_id") String user_id);
@FormUrlEncoded
@POST("pos_distributed.php")
Call<List<ValuesPos>> POS_MODEL_CALL(@Field("user_id") String user_id);
@FormUrlEncoded
@POST(“pos_distributed.php”)
Call POS_MODEL_Call(@Field(“user_id”)字符串user_id);
Backend.java

public void pos_func(String user_id) {

    ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);      

    Call call = apiService.POS_MODEL_CALL(user_id);
    call.enqueue(new Callback() {
        @Override
        public void onResponse(Call call, Response response) {

        }

        @Override
        public void onFailure(Call call, Throwable t) {
            Log.d("sk_log", "Failed! Error = " + t.getMessage());

        }
    });

}
public void pos_func(String user_id) {
        dataArrayList1 = new ArrayList<>();
        ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);


        Call <List<ValuesPos>> call = apiService.POS_MODEL_CALL(user_id);

        call.enqueue(new Callback<List<ValuesPos>>() {
            @Override
            public void onResponse(Call<List<ValuesPos>> call, Response<List<ValuesPos>> response) {
                Log.d("sk_log", "Status POS Code = successsss");
                dataArrayList1 = response.body();

                //ValuesPos valuesPos = (ValuesPos) response.body();
                Log.d("sk_log", "name==="+dataArrayList1.get(0).getName());
                Log.d("sk_log", "name==="+dataArrayList1.get(0).getSubCategory().get(0).getName());
                CustomerCollection.spinner_pos(dataArrayList1);


            }
            @Override
            public void onFailure(Call<List<ValuesPos>> call, Throwable t) {
                Log.d("sk_log", "Failed! Error = " + t.getMessage());               

            }
        });      
    }
public void pos\u func(字符串用户id){
DataArrayList 1=新的ArrayList();
ApiInterface apiService=ApiClient.getClient().create(ApiInterface.class);
Call Call=apiService.POS\u MODEL\u Call(用户id);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
Log.d(“SKU日志”,“状态POS代码=成功”);
dataArrayList1=response.body();
//ValuesPos ValuesPos=(ValuesPos)response.body();
Log.d(“sk_Log”,“name==”+dataArrayList1.get(0.getName());
Log.d(“sk_Log”,“name==”+dataArrayList1.get(0).getSubCategory().get(0).getName());
CustomerCollection.spinner_pos(DataArrayList 1);
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Log.d(“sk_Log”,“Failed!Error=“+t.getMessage());
}
});      
}

:)

以下是适用于我的全部代码。。。(谢谢你的帮助)

修正二类

ApiInterface.java

 @FormUrlEncoded
@POST("pos_distributed.php")
Call<ValuesPos> POS_MODEL_CALL(@Field("user_id") String user_id);
@FormUrlEncoded
@POST("pos_distributed.php")
Call<List<ValuesPos>> POS_MODEL_CALL(@Field("user_id") String user_id);
@FormUrlEncoded
@POST(“pos_distributed.php”)
Call POS_MODEL_Call(@Field(“user_id”)字符串user_id);
Backend.java

public void pos_func(String user_id) {

    ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);      

    Call call = apiService.POS_MODEL_CALL(user_id);
    call.enqueue(new Callback() {
        @Override
        public void onResponse(Call call, Response response) {

        }

        @Override
        public void onFailure(Call call, Throwable t) {
            Log.d("sk_log", "Failed! Error = " + t.getMessage());

        }
    });

}
public void pos_func(String user_id) {
        dataArrayList1 = new ArrayList<>();
        ApiInterface apiService = ApiClient.getClient().create(ApiInterface.class);


        Call <List<ValuesPos>> call = apiService.POS_MODEL_CALL(user_id);

        call.enqueue(new Callback<List<ValuesPos>>() {
            @Override
            public void onResponse(Call<List<ValuesPos>> call, Response<List<ValuesPos>> response) {
                Log.d("sk_log", "Status POS Code = successsss");
                dataArrayList1 = response.body();

                //ValuesPos valuesPos = (ValuesPos) response.body();
                Log.d("sk_log", "name==="+dataArrayList1.get(0).getName());
                Log.d("sk_log", "name==="+dataArrayList1.get(0).getSubCategory().get(0).getName());
                CustomerCollection.spinner_pos(dataArrayList1);


            }
            @Override
            public void onFailure(Call<List<ValuesPos>> call, Throwable t) {
                Log.d("sk_log", "Failed! Error = " + t.getMessage());               

            }
        });      
    }
public void pos\u func(字符串用户id){
DataArrayList 1=新的ArrayList();
ApiInterface apiService=ApiClient.getClient().create(ApiInterface.class);
Call Call=apiService.POS\u MODEL\u Call(用户id);
call.enqueue(新回调(){
@凌驾
公共void onResponse(调用、响应){
Log.d(“SKU日志”,“状态POS代码=成功”);
dataArrayList1=response.body();
//ValuesPos ValuesPos=(ValuesPos)response.body();
Log.d(“sk_Log”,“name==”+dataArrayList1.get(0.getName());
Log.d(“sk_Log”,“name==”+dataArrayList1.get(0).getSubCategory().get(0).getName());
CustomerCollection.spinner_pos(DataArrayList 1);
}
@凌驾
失败时公共无效(调用调用,可丢弃的t){
Log.d(“sk_Log”,“Failed!Error=“+t.getMessage());
}
});      
}

:)

错误:java.lang.IllegalStateException:应为BEGIN_对象,但在第2行第2列路径$处为BEGIN_数组当我读取错误时,我认为问题出在您的ApiInterface上。java,请尝试多个操作,而不是
调用…
尝试Call@ShadabKhan投票胜于感谢之词,请将问题标记为answerederror:java.lang.IllegalStateException:应为BEGIN_对象,但在第2行第2列路径$处为BEGIN_数组当我读取错误时,我认为问题出在您的ApiInterface.java上,请尝试多种方法,而不是
调用…
尝试Call@ShadabKhan投票胜于感谢之词,请将问题标记为已回答