#How could I get the Player of a body?

34 messages ยท Page 1 of 1 (latest)

frosty summit
#
func main() {
    resp, err := http.Get("https://api.wynncraft.com/public_api.php?action=statsLeaderboard&type=player&timeframe=alltime")
    if err != nil {
        panic(err)
    }

    body, err := io.ReadAll(resp.Body)
    resp.Body.Close()
    if err != nil {
        panic(err)
    }
    fmt.Printf("%s", body["Player"])
}```
#

"request":{"timestamp":1663767548,"version":1.3},"data":[{"name":"Maarcus1","uuid":"b7454a9d-ea64-4dea-a4ef-c544d6861b7c","kills":1462,"level":1484,"xp":107068194358,"minPlayed":241932,"tag":"HERO","rank":"Player","displayTag":false,"veteran":false,

#

This is what I get, and i'm trying to get the name's value of it

tacit sedge
#

You need to unmarshall the JSON

frosty summit
#

Unmarshall?? What does that do

tacit sedge
#

There are literally thousands of Golang JSON tutorials out there.

#

(I picked that one completely at random)

frosty summit
#

Thanks

#

Why is Go this hard ๐Ÿ’€

tacit sedge
#

There are also a bunch of very handy tools to help you make the structs from an example JSON string.

frosty summit
#

ty

#

It's completely frozen after I pasted my stuff there lol

#

Is there no easier way to do it?

tacit sedge
#

Easier way to unmarshall JSON?

frosty summit
#

To skip unmarshalling

tacit sedge
#

If you don't unmarshall it, it's just a long string.

frosty summit
#

I guess I'm just not gonna use Go

tacit sedge
#

Okay. You'll have to unmarshall it in any language, though.

#

Well, I guess you can just assert it as an object in JavaScript, but that has a lot of it's very own pitfalls.

frosty summit
#

Not in python

tacit sedge
#

Okay.

frosty summit
#

I am too dumb to understand marshalling

#

so yeah

tacit sedge
#

You're not "dumb" for not understanding something immediately upon coming across it for the first time.

#

You're just new, and that's okay.

#

It's not hard, it's just a little complicated, especially if your background is entirely weakly typed.

#

Stick with it for a while, and I assure you it'll be worth it.

frosty summit
#

I'll try

smoky fjord
tacit sedge
#

Don't get me wrong, it has concrete examples in it, it just also covers some of the theory.

#

...if that even makes sense. I should have a nap.