gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
zrób poprawkę do tego kodu na błąd: Error unmarshaling response body: json: cannot…
- User
zrób poprawkę do tego kodu na błąd: Error unmarshaling response body: json: cannot unmarshal string into Go value of type main.Article
package main
import ( "encoding/json" "fmt" "io/ioutil" "net/http" )
type Article struct { ID int
json:"id"Title stringjson:"title"Description stringjson:"description"}func main() { login := "your_login" apiKey := "your_api_key"
codeurl := "https://dev.to/api/articles/me" req, err := http.NewRequest("GET", url, nil) if err != nil { fmt.Println("Error creating request:", err) return } req.SetBasicAuth(login, apiKey) client := &http.Client{} resp, err := client.Do(req) if err != nil { fmt.Println("Error sending request:", err) return } defer resp.Body.Close() body, err := ioutil.ReadAll(resp.Body) if err != nil { fmt.Println("Error reading response body:", err) return } var articles map[string]Article err = json.Unmarshal(body, &articles) if err != nil { fmt.Println("Error unmarshaling response body:", err) return } for _, article := range articles { fmt.Println("ID:", article.ID) fmt.Println("Title:", article.Title) fmt.Println("Description:", article.Description) fmt.Println() }}
- Assistant
package main
import ( "encoding/json" "fmt" "io/ioutil" "net/http" )
type Article struct { ID int
json:"id"Title stringjson:"title"Description stringjson:"description"}func main() { login := "your_login" apiKey := "your_api_key"
code