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

map type conversion #69

Open
jicui opened this issue Feb 11, 2018 · 1 comment
Open

map type conversion #69

jicui opened this issue Feb 11, 2018 · 1 comment

Comments

@jicui
Copy link

jicui commented Feb 11, 2018

Here is my code example below
func TestJson(t *testing.T){
sjson,:=simplejson.NewJson([]byte(foo()))
v,
:=sjson.Get("listmap").Get("100").String()
fmt.Println(v)//Barcode_PreDelivery_STH-Electronic_Instant_Download
}

func TestJsonMap(t *testing.T){
sjson:=simplejson.New()
listmap:=make(map[string]string)
listmap["100"]="Barcode_PreDelivery_STH-Electronic_Instant_Download"
sjson.Set("listmap",listmap)
v,er:=sjson.Get("listmap").Get("100").String()
fmt.Print(er)//raise type assertion to string failed
fmt.Println(v)//Barcode_PreDelivery_STH-Electronic_Instant_Download

body, _ := sjson.MarshalJSON()
fmt.Println(string(body))

}

func foo() string {
return "{"listmap":{"100":"Barcode_PreDelivery_STH-Electronic_Instant_Download"}}\n";
}

the fist test "TestJson" success to parse the foo string and get value by Get("listmap").Get("100").String()
the second test "TestJsonMap" fails on fetch by
Get("listmap").Get("100").String() and raise "type assertion to string failed"

anything I'm missing here ,appreciated any help

@jicui
Copy link
Author

jicui commented Feb 11, 2018

name = "github.com/bitly/go-simplejson"
version = "0.5.0"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant