Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

encoding/json: Maybe a bug of encoding/json. #11283

conc opened this issue Jun 19, 2015 · 2 comments


None yet
4 participants
Copy link

commented Jun 19, 2015

package main

import (

func main() {
    // jsonDeal([]byte(`{"name":"xiaoming","course":["1111","2222"]}`))
    // jsonDeal([]byte(`{"name":"xiaoming","course":["1111"]}`))
    // jsonDeal([]byte(`{"name":"xiaoming","course":[]}`))
    // jsonDeal([]byte(`{"name":"xiaoming","course":null}`))

type User struct {
    Name   string   `json:"name"`
    Course []string `json:"course"`

func jsonDeal(data []byte) {
    var oneUser User
    if err := json.Unmarshal(data, &oneUser); err != nil {
    fmt.Println("oridata:", string(data))
    fmt.Println("json result:", oneUser)
    fmt.Println("course num:", len(oneUser.Course))

I think len(oneUser.Course) should be 0,but now it is 1.

@ianlancetaylor ianlancetaylor changed the title Maybe a bug of encoding/json. encoding/json: Maybe a bug of encoding/json. Jun 19, 2015

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Jun 19, 2015


This comment has been minimized.

Copy link

commented Jun 19, 2015

I don't see why you think it is a bug. IMO, a [null] array is not the same as a [] array ...


This comment has been minimized.

Copy link

commented Jun 19, 2015

@dspezia ,I understand, [null]string equals [""]string.

@conc conc closed this Jun 19, 2015

@golang golang locked and limited conversation to collaborators Jun 25, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.