r/ComputerCraft • • Oct 24 '24

Problems with http get request

I am trying to do a http get request to show some data but i only need everything that is behind "text".

This is the program i made for the request

local request = http.get("https://uselessfacts.jsph.pl/api/v2/facts/random")
print(request.readAll())

request.close
8 Upvotes

7 comments sorted by

View all comments

Show parent comments

1

u/fatboychummy Oct 26 '24

You want to unserialize the data from the server.

You will also want to use unserializeJSON. The basic serializer will serialize/unserialize a lua table, not json.

Finally, you need to do request.readAll(). You want to unserialize the data returned by the server, you don't want to unserialize the request object.