Это мой первый день с использованием Retrofit для моего андроида projet, и код не показывает categoryname + id, я вижу, что retrofit получает json с debug (true), поэтому связь с сервером API Ok:Первый день с модификацией Android
мой JSON является:
{
categoryDetails: [{
id: "33",
categoryName: "Automotive"
}, {
id: "20",
categoryName: "Baby & kids"
}, {
id: "21",
categoryName: "Books & Media"
}, {
id: "12",
categoryName: "Computers & Accessories"
}, {
id: "7",
categoryName: "Electronics"
}, {
id: "24",
categoryName: "Food"
}]
}
и Java-код:
package org.goodev.retrofitdemo;
import java.util.List;
import android.util.Log;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.http.GET;
import retrofit.http.Path;
public class GitHubClient {
private static final String API_URL = "http://192.168.1.13";
private static final String TAG = null;
static class categoryDetails {
String id;
int categoryName;
@Override
public String toString() {
return id + ", " + categoryName;
}
}
interface Category {
@GET("/seller/category")
void contributors(Callback<List<categoryDetails>> callback);
}
public static void getContributors(Callback<List<categoryDetails>> callback) {
Log.e(TAG, "retrofit");
// Create a very simple REST adapter which points the GitHub API
// endpoint.
RestAdapter restAdapter = new RestAdapter.Builder().setServer(API_URL).build();
// Create an instance of our GitHub API interface.
Category cat = restAdapter.create(Category.class);
// restAdapter.setDebug(true);
// Fetch and print a list of the contributors to this library.
if(callback==null) { Log.w("retrofit", "vide"); }else {
Log.w("retrofit", "no vide");
}
cat.contributors(callback);
}
}
я предпочел использовать переоснащения 2. Вот пример. https://stackoverflow.com/questions/32389584/retrofit-android-not-working-and-has-no-error/46278758#46278758 –