go语言示例代码,
package mainimport "fmt"
import "encoding/json"func main() {list := []int{11, 12, 13, 14, 15}for i,x := range list {fmt.Println("i = ", i, ",x = ", x)}fmt.Println("===")for i := range list {x := list[i]fmt.Println("i=", i, ",x=", x) }fmt.Println("===")map1 := make(map[string]int)map1["a"] = 1map1["b"] = 2for key,value := range(map1) {fmt.Println("key = ", key, ",value = ", value)}fmt.Println("===")new_linkidlist := make([][2]int64, 0) //声明一个切片,其中每个元素是一个元素个数为2的数组new_linkidlist = append(new_linkidlist, [2]int64{1, 11})new_linkidlist = append(new_linkidlist, [2]int64{2, 22})new_linkidlist = append(new_linkidlist, [2]int64{3, 33})jsonlink, _ := json.Marshal(new_linkidlist)fmt.Println("jsonlink = ", jsonlink)var res [][2]int64err := json.Unmarshal(jsonlink, &res)if err != nil {fmt.Println("解析json报错,", err)} else {fmt.Println("res=", res)}}
输出结果为,
i = 0 ,x = 11
i = 1 ,x = 12
i = 2 ,x = 13
i = 3 ,x = 14
i = 4 ,x = 15
===
i= 0 ,x= 11
i= 1 ,x= 12
i= 2 ,x= 13
i= 3 ,x= 14
i= 4 ,x= 15
===
key = a ,value = 1
key = b ,value = 2
===
jsonlink = [91 91 49 44 49 49 93 44 91 50 44 50 50 93 44 91 51 44 51 51 93 93]
res= [[1 11] [2 22] [3 33]]