开始学习golang.任务:获取Json和Unmarshall.但我错了:
Json tag but not exported
Run Code Online (Sandbox Code Playgroud)
如何导出未导出的字段,然后使用方法实现它?
这是代码:
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
)
type Time struct {
time
}
type time struct {
id string `json:"$id"`
currentDateTime string `json:"currentDateTime,string"`
utcOffset float64 `json:"utcOffset,string"`
isDayLightSavingsTime bool `json:"isDayLightSavingsTime,string"`
dayOfTheWeek string `json:"dayOfTheWeek,string"`
timeZoneName string `json:"timeZoneName,string"`
currentFileTime float64 `json:"currentFileTime,string"`
ordinalDate string `json:"ordinalDate,string"`
serviceResponse string `json:"serviceResponse,string"`
}
func (t *Time) GetTime() (Time, error) {
result := Time{}
return result, t.Timenow(result)
}
func (t *Time) Timenow(result interface{}) error {
res, err := http.Get("http://worldclockapi.com/api/json/utc/now") …Run Code Online (Sandbox Code Playgroud) 我有
array1 = [1,2,3,4,5];
array2 = ["one","two","three","four","five"];
Run Code Online (Sandbox Code Playgroud)
我希望得到第一个(和其他)元素等array3所有元素的位置.array1array2
例如:
array3 = ["one 1", "two 1", "three 1", "four 1", "five 1", "one 2", "two 2", "three 2", "four 2", "five 2"...]
Run Code Online (Sandbox Code Playgroud)
我知道我需要使用for循环,但我不知道该怎么做.