Recipe - Food - Nutrition

FREEMIUM
Verified
Por David | Atualizado 22 दिन पहले | Food
Popularidade

9.9 / 10

Latência

517ms

Nível de serviço

100%

Health Check

N/A

Voltar para todas as discussões

Get Recipes Returned JSON

Rapid account: Deleted
[deleted]
9 वर्ष पहले

Hi I am having trouble using the JsonArray that is returned from calling “https://spoonacular-recipe-food-nutrition-v1.p.mashape.com/recipes/findByIngredients?ingredients=eggs, milk”.

The error I keep getting is “JsonArray cannot be cast as JsonObject”. I am successful in retrieving any queries that involve just one item but when I need a list of items, I run into this problem.

Any ideas on how to fix it? I’ve checked StackOverflow and have tried all solutions on the first page of the google results.

Rapid account: Spoonacular
spoonacular Commented 8 वर्ष पहले

Hi SmartChef,

do you still need evaluation access to the API?

Best,
David

Rapid account: Spoonacular
spoonacular Commented 9 वर्ष पहले

great to hear 😃

Rapid account: Deleted
[deleted] Commented 9 वर्ष पहले

I had one last attempt at it before I saw your response and it worked. If I have problems in the future, I will try what you just suggested.

What worked was:

@GET("/recipes/{id}")
public JsonArray getRecipeByIngredient(@Path(value = “id”, encode = false) String id);

and the string that was passed in was “findByIngredients?ingredients=whatever_was_searched_separated_by_%2C”

Rapid account: Spoonacular
spoonacular Commented 9 वर्ष पहले

Can’t you do something like this:

@Get("/{search}/") public JsonArray getRecipeByIngredient(@Path(“search”) String search, @Query(“ingredients”) String ingredients, @Query(“number”) int number);

and then pass

search: /recipes/findByIngredients

ingredients: eggs

number: 5

Rapid account: Deleted
[deleted] Commented 9 वर्ष पहले

So what would be a solution? Not sure what I can do

Rapid account: Spoonacular
spoonacular Commented 9 वर्ष पहले

maybe that code url encodes your parameter and you get the “?” replace with its url encoded version? That would then lead to an invalid request…

Rapid account: Deleted
[deleted] Commented 9 वर्ष पहले

I am using

@GET("/recipes/findByIngredients")
public JsonArray getRecipeByIngredient(@Query(“search”) String search);

When I do this it works:
@Get("/recipes/findByIngredients?ingredients=eggs%2Cmilk&number=5)
public JsonArray getRecipeByIngredient();

Another method that I wrote that works is

@GET("/recipes/{id}/information")
public RecipeModel getRecipe(@Path(“id”) String id);

So I tried:

@Get("/{search}")
public JsonArray(getRecipeByIngredient(@Path(“search”) String search);

and passed “recipes/findByIngredients?ingredients=eggs%2Cmilk&number=5” into the method
but got a 400 bad request error. Same exact request but now there is an error.

Rapid account: Spoonacular
spoonacular Commented 9 वर्ष पहले

Can you send me the URL for which you get the 500er error? the one from your first post works for me.

Rapid account: Deleted
[deleted] Commented 9 वर्ष पहले

So I am now getting a “500 Internal Server” error when I query the server. My original problem was that I somehow forgot to provide search parameters when I made the query.

Any ideas on why the 500 Internal Server error is being thrown?

Rapid account: Deleted
[deleted] Commented 9 वर्ष पहले

I could not use Unirest because Android was not allowing it. I am using Retrofit to make the calls to server. I have tried returning a JsonArray and still got errors. Do you know how to use Retrofit?

Junte-se à discussão - adicione o comentário abaixo:

Efetue login / inscreva-se para postar novos comentários