Thank you so much you are a life saver i can now receive the recipes and everything is going well you are an angel. I just hope i can get the app to translate the Json text into normal text in time. <33 @ABG
Once I am done with the competition i will post the app .aix in this conversation so you can see it <33
I have been trying to translate the JSON text for the recipes that I receive from spoonacular and i keep getting the same error can anyone explain to me what it means ?
and this is my code :
I also tried to separate it in pairs (keys and values) like I have seen many tutorials and people too but the JSON text that I receive is not in pairs and I don't really understand alot about JSON as my teacher didn't teach me about it but I tried to learn from here : Using Web APIs with JSON (mit.edu) and it was helpful but i only managed to understand the basics . so if anyone can explain the problem that i am going through or provide me with any link to a useful tutorial i will be very grateful <33
can you paste here exactly what you are receiving in the responseContent (before any conversion)?
Not a screenshot of your responseContent, but the content of the responseContent. Check here how do it and then paste here the received response:
How to show raw responseContent from your app when debugging - Tutorials and Guides - MIT App Inventor Community
like this?
[{"id":654515,"image":"https://img.spoonacular.com/recipes/654515-312x231.jpg","imageType":"jpg","likes":1,"missedIngredientCount":2,"missedIngredients":[{"aisle":"Produce","amount":5,"id":2004,"image":"https://img.spoonacular.com/ingredients_100x100/bay-leaves.jpg","meta":["(from my garden)"],"name":"pandan leaves click here cut to 2" length","original":"5 Pandan leaves click here (from my garden) cut to 2" length","originalName":"Pandan leaves click here (from my garden) cut to 2" length","unit":"","unitLong":"","unitShort":""},{"aisle":"Nut butters, Jams, and Honey","amount":6,"id":19296,"image":"https://img.spoonacular.com/ingredients_100x100/honey.png","meta":["to taste"],"name":"honey or","original":"6 tablespoons Honey or to taste","originalName":"Honey or to taste","unit":"tablespoons","unitLong":"tablespoons","unitShort":"Tbsp"}],"title":"Pandan Smoothie","unusedIngredients":,"usedIngredientCount":2,"usedIngredients":[{"aisle":"Produce","amount":100,"id":11206,"image":"https://img.spoonacular.com/ingredients_100x100/cucumber.jpg","meta":["cut into small cubes"],"name":"cucumber","original":"100 grams Cucumber, cut into small cubes","originalName":"Cucumber, cut into small cubes","unit":"grams","unitLong":"grams","unitShort":"g"},{"aisle":"Produce","amount":3,"id":9200,"image":"https://img.spoonacular.com/ingredients_100x100/orange.png","meta":["peeled","quartered"],"name":"oranges","original":"3 Oranges, peeled and quartered","originalName":"Oranges, peeled and quartered","unit":"","unitLong":"","unitShort":""}]}, {"id":639512,"image":"https://img.spoonacular.com/recipes/639512-312x231.png","imageType":"png","likes":7,"missedIngredientCount":4,"missedIngredients":[{"aisle":"Produce","amount":2,"id":11959,"image":"https://img.spoonacular.com/ingredients_100x100/arugula-or-rocket-salad.jpg","meta":,"name":"arugula","original":"2 cups arugula","originalName":"arugula","unit":"cups","unitLong":"cups","unitShort":"cup"},{"aisle":"Produce","amount":2,"id":11429,"image":"https://img.spoonacular.com/ingredients_100x100/radishes.jpg","meta":["thinly sliced"],"name":"radish","original":"2 radish, thinly sliced","originalName":"radish, thinly sliced","unit":"","unitLong":"","unitShort":""},{"aisle":"Produce","amount":1,"id":11291,"image":"https://img.spoonacular.com/ingredients_100x100/spring-onions.jpg","meta":["chopped"],"name":"green onion","original":"1 green onion, chopped","originalName":"green onion, chopped","unit":"","unitLong":"","unitShort":""},{"aisle":"Seafood","amount":8,"id":10015172,"image":"https://img.spoonacular.com/ingredients_100x100/scallops.jpg","meta":,"name":"scallops","original":"8 scallops","originalName":"scallops","unit":"","unitLong":"","unitShort":""}],"title":"Citrus Arugula Salad with Seared Scallops","unusedIngredients":,"usedIngredientCount":2,"usedIngredients":[{"aisle":"Produce","amount":1,"id":9200,"image":"https://img.spoonacular.com/ingredients_100x100/orange.png","meta":,"name":"cara cars orange","original":"1 cara cars orange","originalName":"cara cars orange","unit":"","unitLong":"","unitShort":""},{"aisle":"Produce","amount":0.5,"extendedName":"english persian cucumber","id":10111205,"image":"https://img.spoonacular.com/ingredients_100x100/english-cucumber.png","meta":["english","thinly sliced","(or cucumber)"],"name":"persian cucumber","original":"1/2 persian cucumber (or english cucumber), thinly sliced","originalName":"persian cucumber (or english cucumber), thinly sliced","unit":"","unitLong":"","unitShort":""}]}]
I don't know what to do with it, this is exactly how i received it from the spoonacular API . is the issue with the Api itself or my app
You can try to manipulate the response received to delete all those malformed parts:
the question is if for other request you will have responses with other weird fields....
For example, with the above example of @ABG this example will not work...
(EDIT: I have changed the example by other more generic)
Other option could be extract the info directly from the response string but this can be quite cumbersome depending on the information you want to extract.
I'm so sorry, I made a mistake. These fields without values are due to the fact that when you copied the JSON that you have left, the empty fields [ ] have been pasted as and then they have not been pasted correctly in my example. Apologies. By removing that part of "length" you should be able to decode it correctly:
Thank you for your reply buddy. Will this work though for different recipes? since my app will take different variables based on the users preferences and have the API retrieve recipes for them. I will continue working on my app and i will see if your code fixes the problem.<333
Looking to the @ABG examples:
name": "pandan leaves click here cut to 2\" length",
you can se the double quotes after the 2 are escaped (2 \ ")...in what you have pasted that double quotes are not escaped (2").
This difference is why you have to put that first additional block removing "length "".
But if your response have that double quoted escaped like in the other examples (maybe other error copy-pasting) then you don't need that additional block.
It is important to find out that because what works for one scenario will not work for the other so, try without the additional block:
I will try both and tomorrow I will show you the results. thanks! <33
Sorry for the mistakes...
I found the recipe JSON unparseable using the DecodeJSONAsDictionaries block, but the older DecodeJSON block was able to parse it without errors, albeit into lists of pairs.
So here is some rudimentary browsing and display code:
spoonacular.aia (7.5 KB)
I leave it up to you to prettify the output.
One last note about spoonacular recipes.
I didn't see anything about preparation instructions.
Maybe they just do salads?
don't say that friend! you've done more than enough to help me thank you! <33