Sobes.tech
Junior — Middle

Quale struttura dati nel linguaggio Go è analoga al formato JSON?

sobes.tech AI

Risposta dell'AI

Nel linguaggio Go, una struttura dati simile al formato JSON è map[string]interface{} o strutture (struct), che possono essere serializzate e deserializzate in JSON usando il pacchetto encoding/json.

Esempio di utilizzo di una mappa per memorizzare dati simili a JSON:

import (
    "encoding/json"
    "fmt"
)

func main() {
    data := map[string]interface{}{
        "name": "Alice",
        "age": 30,
        "isMember": true,
    }

    jsonBytes, _ := json.Marshal(data)
    fmt.Println(string(jsonBytes))
}