You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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
The text was updated successfully, but these errors were encountered:
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
}
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
The text was updated successfully, but these errors were encountered: