我正在 Android Studio 中制作一个应用程序,我想使用 API 来制作烹饪食谱,我从使用 Android Studio 和 Java 的 API 得到以下响应:API响应 "q" : "pollo", "from" : 0, "to" : 10, "params" : { "sane" : [ ], "q" : [ "pollo" ], "app_id" : [ "02" ], "app_key" : [ "\n66b" ] }, "more" : true, "count" : 1000, "hits" : [ { "recipe" : { "uri" : "http://www.edamam.com/ontologies/edamam.owl#recipe_d56f75c72ab67a45174441af1efe4473", "label" : "Pollo con Crema a las Hierbas", "image" : "http://cdn.kiwilimon.com/recetaimagen/23127/thumb120x90-15802.jpg", "source" : "KiwiLimon", "url" : "http://www.kiwilimon.com/receta/carnes-y-aves/pollo-con-crema-a-las-hierbas", "shareAs" : "http://www.edamam.com/recipe/pollo-con-crema-a-las-hierbas-d56f75c72ab67a45174441af1efe4473/pollo", "yield" : 42.0,并继续更多“食谱”,我想要的是只获得所有食谱必须能够在我的应用程序中显示的命中数组,问题是我收到以下错误:Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $我知道这是因为它需要一个数组并获得一个 JSON 对象,但我不知道如何解析它,我有我的 Recipe 模型类和 RecipeService 服务,我在 MainActivity 中管理所有内容,我在一些答案中看到我必须做一个中间响应,但我不明白如何在我的代码中实现它,然后我展示了处理所有这些的类。配方类(型号):public class Recipe { private String label; private String image; private String source; private String shareAs; private List<String> dietLabels; private List<String> healthLabels; private List<String> cautions; private List<String> ingredientLines; private List<String> ingredients; private double calories; private double totalWeight; private List<String> totalNutrients; private List<String> totalDaily; public String getLabel() { return label; } . . .食谱服务类: public interface RecipeService { String API_ROUTE = "/search"; String API_KEY = "&app_key=" + Credentials.API_KEY; String APP_ID = "&app_id=" + Credentials.APP_ID; //String query = ""; @GET(API_ROUTE) Call< List<Recipe> > getRecipe(@Query("q") String q);}
1 回答
慕工程0101907
TA贡献1887条经验 获得超5个赞
添加回答
举报
0/150
提交
取消