【发布时间】:2016-12-16 10:01:55
【问题描述】:
我已经查看了大多数与 prestashop 相关的问题。其中一些人说 prestashop 没有 api。看看这个链接
http://online.fastchef.in/api/customers/12?output_format=JSON
它以 json 形式给出结果。唯一的事情是解析这个表单。但仍然出现错误 我的代码:MainActivity
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(API_BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
int id=Integer.parseInt(mEditText.getText().toString());
PrestaShopClient client =retrofit.create(PrestaShopClient.class);
Call<Customer> hj=client.getCustomer(id);
hj.enqueue(new Callback<Customer>() {
@Override
public void onResponse(Call<Customer> call, Response<Customer> response) {
int status = response.code();
Customer customer = response.body();
mTextView.setText(customer.getFirstname());
}
@Override
public void onFailure(Call<Customer> call, Throwable t) {
}
});
PrestaShop 客户端:
public interface PrestaShopClient {
@GET("customers/{id}?output_format=JSON")
Call<Customer> getCustomer(@Path("id") int id);
}
帮帮我...这个问题花了我半天时间;(
【问题讨论】:
标签: android json parsing xml-parsing prestashop-1.6