0
{"info":-[-{"success":true,
"object":-[-{"id":"743",
"pagetitle":"\u041a\u044d\u0448-\u042e",
"price":"7000-12000",
"titleCat":"\u0420\u0435\u0441\u0442\u043e\u0440\u0430\u043d\u044b",
"map":"43.225252604744355,76.95571602834801",
"img":"assets\/uploads\/97\/2016-09-04_11-00-22_2.jpg",
"halal":"1",
"isAkc":"",
"address":"\u0433.\u0410\u043b\u043c\u0430\u0442\u044b, \u0425\u0430\u0434\u0436\u0438 \u041c\u0443\u043a\u0430\u043d\u0430 43, \u0443\u0433 \u041c\u0435\u0434\u0438\u043a\u0443\u043b\u043e\u0432\u0430.",
"work-day":"\u043f\u043d-\u0447\u0442 \u0441 10:00 \u0434\u043e 01:00 \u043f\u0442-\u0441\u0431 \u0441 11:00 \u0434\u043e 02:00",
"rating":"5"
},

_

 @GET("?act=object&cid=10&sort=1")
Call<ResturantResponse> getResturantList();

public class ResturantResponse {
@SerializedName("object")
private List<Resturant> object;

public List<Resturant> getObject() {
    return object;
}

public void setObject(List<Resturant> object) {
    this.object = object;
}
}


@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.recycler_view_resturant);

    ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
    Call<ResturantResponse> call = apiInterface.getResturantList();
    call.enqueue(new Callback<ResturantResponse>() {
        @Override
        public void onResponse(Call<ResturantResponse> call, Response<ResturantResponse> response) {
            List<Resturant> resturants = response.body().getObject();
            recyclerView.setAdapter(new ResturantAdapter(resturants,R.layout.card_view_resturant,getActivity().getApplicationContext()));
        }

        @Override
        public void onFailure(Call<ResturantResponse> call, Throwable t) {
            Log.e("resturant",t.toString());
        }
    });
}

я так написал Response но ответ пустой.

2
  • можно полностью json? по моему, структура не соответствует ответу. и минусы какие-то странные....
    – dramf
    19 окт 2016 в 13:12
  • вот json {"info":[{"success":true,"object":[{"id":"743","pagetitle":"\u041a\u044d\u0448-\u042e","price":"7000-12000","titleCat":"\u0420\u0435\u0441\u0442\u043e\u0440\u0430\u043d\u044b","map":"43.225252604744355,76.95571602834801","img":"assets\/uploads\/97\/2016-09-04_11-00-22_2.jpg","halal":"1","isAkc":"","address":"\u0433.\u0410\u043b\u043c\u0430\u0442\u044b, \u0425\u0430\u0434\u0436\u0438 \u041c\u0443\u043a\u0430\u043d\u0430 43, \u0443\u0433 \u041c\u0435\u0434\u0438\u043a\u0443\u043b\u043e\u0432\u0430.","work-day":"\u043f\u043d-\u0447\u0442 \u0441 10:00 \u0434\u043e 01:00 \u043f\u0442
    – Mr.Baga
    20 окт 2016 в 4:17

1 ответ 1

0

Судя по json YourResponse.java:

public class YourResponse {
private final Info info;

public YourResponse(Info info) {
    this.info = info;
}

public class Info {
    private final boolean success;
    private final List<Resturant> object;

    public Info(boolean success, List<YourObject> object) {
        this.success = success;
        this.object = object;
    }
}

public class Resturant {
    private final String id;
    private final String pagetitle;
    private final String price;
    private final String titleCat;
    private final String map;
    private final String img;
    private final String halal;
    private final String isAks;
    private final String address;
    @SerializedName("work-day")
    private final String workDay;
    private final String rating;

    public Resturant(String id, String pagetitle, String price, String titleCat, String map, String img, String halal, String isAks, String address, String workDay, String rating) {
        this.id = id;
        this.pagetitle = pagetitle;
        this.price = price;
        this.titleCat = titleCat;
        this.map = map;
        this.img = img;
        this.halal = halal;
        this.isAks = isAks;
        this.address = address;
        this.workDay = workDay;
        this.rating = rating;
    }
}
}

Ну и get-еры для каждого поля

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.