- Sky
- Blueberry
- Slate
- Blackcurrant
- Watermelon
- Strawberry
- Orange
- Banana
- Apple
- Emerald
- Chocolate
- Charcoal
Bitstrips
-
Content Count
2 -
Joined
-
Last visited
Posts posted by Bitstrips
-
-
It seems completely funny but I am actually trying to get through this for the last 2 days:
I try to access weather data through the OpenWeatherMap.org API wich seems to work fine with internet.request(url).
The problem is just that it returns me the JSON as a table instead of a String. I tried to access fields of that table but everything seems to return nil. I just can't get to access anything from that table. There are tons of JSON serialization librarys out there but they all need the JSON as a String. I am completely lost rn.
This is the API response that gets stored as a table for some reason:
{"coord":{"lon":7.68,"lat":52.85},"weather":[{"id":500,"main":"Rain","description":"light rain","icon":"10n"}],"base":"stations","main":{"temp":10.51,"pressure":999,"humidity":66,"temp_min":10,"temp_max":11.11},"visibility":10000,"wind":{"speed":5.1,"deg":230},"rain":{"3h":0.11},"clouds":{"all":92},"dt":1552771115,"sys":{"type":1,"id":1871,"message":0.0045,"country":"DE","sunrise":1552714945,"sunset":1552757625},"id":2810860,"name":"Werlte","cod":200}
My Lua code couldn't be simpler:
local web = require("internet") local data = web.request(<API_LINK>) -- data is of type table and I don't know how to get any values. Tried so many combinations on indices. -- For each loop works to loop through everything though
Need urgent advice on working with API data through internet.request()
in Requests
Posted
So basicly I fixed it in a different matter:
While iterating through data with ipair I managed to see that data contained two functions for some reason appliable on data. When I wrote the variable as a function => data() It showed me the correct JSON String and I could use it with the json lua library to create a usable table. Thanks for your responses tho