Parse the entries

This commit is contained in:
Huy-Ngo 2020-10-28 20:51:07 +07:00
parent 1f84b1d5b8
commit c300302227
1 changed files with 48 additions and 0 deletions

48
main.go Normal file
View File

@ -0,0 +1,48 @@
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
func main() {
response, err := http.Get("https://en.wiktionary.org/api/rest_v1/page/definition/général")
if err != nil {
fmt.Print(err.Error())
os.Exit(1)
}
responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
var result interface{}
err = json.Unmarshal([]byte(responseData), &result)
entries := result.(map[string]interface{})
for key, value := range entries {
switch typ := value.(type) {
case string:
fmt.Println(key, "is string", typ)
case int:
fmt.Println(key, "is int", typ)
case []interface{}:
fmt.Println(key, "is an array:")
for i, u := range typ {
fmt.Println(i, u)
}
default:
fmt.Println(key, "is some other type")
}
}
}