“Peta Golang” Kode Jawaban

inisialisasi peta di golang

// By default maps in Go behaves like a default dictionary in python
m := make(map[string]int)

m["Dio"] = 3
m["Jonathan"] = 1
Joseph Joestar

Pergi Tambahkan ke Peta

m := make(map[string]int)
m["numberOne"] = 1
m["numberTwo"] = 2
Navid2zp

Peta Golang

package main
import "fmt"

func main() {

  object := map[string]string{
    "name": "john doe",
  }
  
  arrayObject := []map[string]string{
    map[string]string{ "name": "john doe"},
    map[string]string{"name": "jane doe"},
  }

  usingMake := make(map[string] string)
  usingMake["name"] = "max cavalera"
  
  fmt.Printf("this is object %v \n", object)
  fmt.Printf("this is array object %v \n", arrayObject)
  fmt.Printf("using make method %v \n", usingMake)
}
Restu Wahyu Saputra

Peta Golang

package main

import (
	"encoding/json"
	"fmt"
	"net/http"
)

type Address struct {
	Street  string `json:"street"`
	Suite   string `json:"suite"`
	Zipcode string `json:"zipcode"`
}

type Users struct {
	Name string `json:"name"`
	Age  uint   `json:"age"`
}

func Mapping() {
   // users 1 example
	var users1 map[string]interface{}

	users1 = map[string]interface{}{"name": "john doe", "age": 23}

   // users 2 example
	users2 := map[string]interface{}{"name": "john doe", "age": 23}

   // users 3 example
	users3 := make(map[string]interface{})
	users3 = map[string]interface{}{"name": "John doe", "age": 23}

   // users 4 example
	var users4 map[string]interface{} = map[string]interface{}{"name": "John doe", "age": 23}

	fmt.Printf("Object mapping 1 %#v \n", users1)
	fmt.Printf("Object mapping 2 %#v \n", users2)
	fmt.Printf("Object mapping 3 %#v \n", users3)
	fmt.Printf("Object mapping 4 %#v \n", users4)
}

func ArrayMapping() {
   // users 1 example
	var users1 []map[string]interface{}

	users1 = []map[string]interface{}{
		map[string]interface{}{"name": "john doe", "age": 23},
	}

   // users 2 example
	users2 := []map[string]interface{}{
		map[string]interface{}{"name": "john doe", "age": 23},
	}

   // users 2 example
	users3 := make([]map[string]interface{}, 1)
	users3 = []map[string]interface{}{
		map[string]interface{}{"name": "John doe", "age": 23},
	}

   // users 4 example
	var users4 []map[string]interface{} = []map[string]interface{}{map[string]interface{}{"name": "John doe", "age": 23}}

	fmt.Printf("Array object mapping 1 %#v \n", users1)
	fmt.Printf("Array object mapping 2 %#v \n", users2)
	fmt.Printf("Array object mapping 3 %#v \n", users3)
	fmt.Printf("Array object mapping 4 %#v \n", users4)
}

func main() {
	Mapping()
	fmt.Printf("\n")
	ArrayMapping()
}
Restu Wahyu Saputra

Peta Golang

myMap := make(map[(key type)](value type))
Itchy Ibex

Jawaban yang mirip dengan “Peta Golang”

Pertanyaan yang mirip dengan “Peta Golang”

Lebih banyak jawaban terkait untuk “Peta Golang” di Go

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya