bitly / go-simplejson

a Go package to interact with arbitrary JSON
MIT License
3.76k stars 498 forks source link

implicit assignment of unexported field 'data' in simplejson.Json literal #50

Closed se77en closed 8 years ago

se77en commented 8 years ago

When I use like &simplejson.Json{v} (v is a interface read from file and it's actual data structure is map[string]interface{}), then show this error. Details:

A json file named abcd

{
    "pids": [
        { 
            "pid": 168043, 
            "target_regions": [
                40, 
                25, 
                43, 
                299, 
                240, 
                256, 
                294, 
                259, 
                108, 
                63, 
                65
            ]
         },
        { 
            "pid": 168044, 
            "target_regions": [
                40, 
                25, 
                43, 
                299, 
                240, 
                256, 
                294, 
                259, 
                108, 
                63, 
                65,
                68
            ]
        }
    ]
}

And the go file is

package main    

import (
    "fmt"
    "io/ioutil"    

    sjson "github.com/bitly/go-simplejson"
)    

type pidInfo struct {
    Pid           uint64   `json:"pid"`
    TargetRegions []uint32 `json:"target_regions"`
}    

type pidUnitInfo struct {
    Pid2Info map[uint64]*pidInfo
}    

func build() error {
    content, _ := ioutil.ReadFile("./abcd")
    json, err := sjson.NewJson(content)
    if err != nil {
        return err
    }
    newPidUnitInfo(json)
    return nil
}    

func newPidUnitInfo(json *sjson.Json) (*pidUnitInfo, error) {
    newInfo := new(pidUnitInfo)
    newInfo.buildPid2Info(json)
    return nil, nil
}    

func (pui *pidUnitInfo) buildPid2Info(json *sjson.Json) error {
    raw, ok := json.CheckGet("pids")
    if !ok {
        return fmt.Errorf("not found json key %v", "pids")
    }
    pids, err := raw.Array()
    if err != nil {
        return err
    }
    pui.Pid2Info = make(map[uint64]*pidInfo, len(pids))
    for _, v := range pids {
        fmt.Println(v)
        m := &sjson.Json{v}
        fmt.Println(m)
    }
    return nil
}    

func main() {
    build()
}

When I execute it, show implicit assignment of unexported field 'data' in simplejson.Json literal at this line m := &sjson.Json{v}.

se77en commented 8 years ago

My stupid error, sorry!