• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang json.Get函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中encoding/json.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: iotPost

func iotPost(w http.ResponseWriter, r *http.Request) {
	fmt.Println("Post")
	// receive posted data
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		fmt.Println(err)
		fmt.Fprint(w, "IoT failed")
		return
	}
	json, err := simplejson.NewJson(body)
	if err != nil {
		fmt.Println("error in NewJson:", err)
		return
	}
	payload := json.Get("payload")
	payload_str, err := payload.String()
	if err != nil {
		fmt.Println("Couldn't get payload")
		return
	}
	created_at, err := json.Get("created_at").String()
	if err != nil {
		// If the created at time doesn't come with the
		// JSON object then generate it with RFC3339 format
		t := time.Now()
		created_at = t.UTC().Format("2006-01-02T15:04:05Z07:00")
	}
	fmt.Println("Got payload " + payload_str + " at " + created_at)
	renderOk(w, []byte(`{"content": body}`))
}
开发者ID:jlhonora,项目名称:iot-go,代码行数:30,代码来源:iot.go


示例2: BenchmarkGoSimplejsonSmall

func BenchmarkGoSimplejsonSmall(b *testing.B) {
	for i := 0; i < b.N; i++ {
		json, _ := simplejson.NewJson(smallFixture)

		json.Get("uuid").String()
		json.Get("tz").Float64()
		json.Get("ua").String()
		json.Get("st").Float64()

		nothing()
	}
}
开发者ID:qband,项目名称:down,代码行数:12,代码来源:benchmark_small_payload_test.go


示例3: BenchmarkUjsonSmall

func BenchmarkUjsonSmall(b *testing.B) {
	for i := 0; i < b.N; i++ {
		json, _ := ujson.NewFromBytes(smallFixture)

		json.Get("uuid").String()
		json.Get("tz").Float64()
		json.Get("ua").String()
		json.Get("st").Float64()

		nothing()
	}
}
开发者ID:qband,项目名称:down,代码行数:12,代码来源:benchmark_small_payload_test.go


示例4: BenchmarkGoSimpleJsonMedium

/*
   github.com/bitly/go-simplejson
*/
func BenchmarkGoSimpleJsonMedium(b *testing.B) {
	for i := 0; i < b.N; i++ {
		json, _ := simplejson.NewJson(mediumFixture)
		person := json.Get("person")
		person.Get("name").Get("fullName").String()
		person.Get("github").Get("followers").Float64()
		json.Get("company")
		arr, _ := person.Get("gravatar").Get("avatars").Array()

		for _, el := range arr {
			nothing(el.(map[string]interface{})["url"])
		}
	}
}
开发者ID:qband,项目名称:down,代码行数:17,代码来源:benchmark_medium_payload_test.go


示例5: ListTables

func (s *Server) ListTables() ([]string, error) {
	var tables []string

	query := NewEmptyQuery()

	jsonResponse, err := s.queryServer(target("ListTables"), query)

	if err != nil {
		return nil, err
	}

	json, err := simplejson.NewJson(jsonResponse)

	if err != nil {
		return nil, err
	}

	response, err := json.Get("TableNames").Array()

	if err != nil {
		message := fmt.Sprintf("Unexpected response %s", jsonResponse)
		return nil, errors.New(message)
	}

	for _, value := range response {
		if t, ok := (value).(string); ok {
			tables = append(tables, t)
		}
	}

	return tables, nil
}
开发者ID:PuerkitoBio,项目名称:goamz,代码行数:32,代码来源:table.go


示例6: Execute

func (batchWriteItem *BatchWriteItem) Execute() (map[string]interface{}, error) {
	q := NewEmptyQuery()
	q.AddWriteRequestItems(batchWriteItem.ItemActions)

	jsonResponse, err := batchWriteItem.Server.queryServer(target("BatchWriteItem"), q)

	if err != nil {
		return nil, err
	}

	json, err := simplejson.NewJson(jsonResponse)

	if err != nil {
		return nil, err
	}

	unprocessed, err := json.Get("UnprocessedItems").Map()
	if err != nil {
		message := fmt.Sprintf("Unexpected response %s", jsonResponse)
		return nil, errors.New(message)
	}

	if len(unprocessed) == 0 {
		return nil, nil
	} else {
		return unprocessed, errors.New("One or more unprocessed items.")
	}

}
开发者ID:nalin-humin,项目名称:goamz,代码行数:29,代码来源:item.go


示例7: BenchmarkUjsonMedium

func BenchmarkUjsonMedium(b *testing.B) {
	for i := 0; i < b.N; i++ {
		json, _ := ujson.NewFromBytes(mediumFixture)

		person := json.Get("person")

		person.Get("name").Get("fullName").String()
		person.Get("github").Get("followers").Float64()
		json.Get("company").String()

		arr := person.Get("gravatar").Get("avatars").Array()
		for _, el := range arr {
			el.Get("url").String()
		}

		nothing()
	}
}
开发者ID:qband,项目名称:down,代码行数:18,代码来源:benchmark_medium_payload_test.go


示例8: StartClient

func StartClient(configFile string, done chan bool) {
	b, err := ioutil.ReadFile(configFile)
	if err != nil {
		fmt.Println(configFile, " not found")
		go func() {
			done <- false
		}()
		return
	}
	json, _ := simplejson.NewJson(b)
	ip := json.Get("ip").MustString("127.0.0.1")
	port := json.Get("port").MustInt(6776)

	monitors := json.Get("monitors").MustMap()

	for k, v := range monitors {
		monitored, _ := v.(string)
		go startWork(ip, port, k, monitored, time.Minute)
	}
}
开发者ID:huuzkee-foundation,项目名称:filesync,代码行数:20,代码来源:client.go


示例9: TrySimpleJson

func TrySimpleJson() {
	body := []byte(jsonString)
	json, _ := simplejson.NewJSON(body)
	P(json.Get("data", "content", "body").String())
	content := json.Get("data", "content")
	P("content on *json-type: ", content)
	byte_data, _ := json.Get("data", "content").MarshalJSON()
	// P("not marshaled, just use string(): ", string(json.Get("data", "content")))		// failed
	P("content MarshalJsoned: ", string(byte_data))
	// not follow at archture:
	P("not follow archery: ", json.Get("title"))

	json2_byte := []byte(json2)
	json, _ = simplejson.NewJSON(json2_byte)
	// for i, v := range json.Get("conversations").Array() {
	//  P(i, v)
	// }
	qa_activity := json.Get("conversations").JSONArray()[0].Get("data", "qa_activity")
	qa_activity1, _ := qa_activity.MarshalJSON()
	P("stringed qa_activity", string(qa_activity1))
	P("action: ", qa_activity.Get("action").String())
	P("num_unread: ", qa_activity.Get("num_unread").Int())
	P("thread_id: ", qa_activity.Get("thread_id").String())
	data_raw := json.Get("conversations").JSONArray()[0].Get("data_raw").String()
	P("raw_data_raw: ", data_raw)
}
开发者ID:zykzhang,项目名称:practice,代码行数:26,代码来源:chap1.go


示例10: GetEmailAddress

func (p *SonyXperiaProvider) GetEmailAddress(s *SessionState) (string, error) {
	req, err := http.NewRequest("GET",
		p.ProfileUrl.String()+"?access_token="+s.AccessToken, nil)
	if err != nil {
		log.Printf("failed building request %s", err)
		return "", err
	}
	json, err := api.Request(req)
	if err != nil {
		log.Printf("failed making request %s", err)
		return "", err
	}
	return json.Get("email").String()
}
开发者ID:valtech,项目名称:oauth2_proxy,代码行数:14,代码来源:sonyxperia.go


示例11: GetEmailAddress

func (p *PhabricatorProvider) GetEmailAddress(s *SessionState) (string, error) {
	req, err := http.NewRequest("GET",
		p.ProfileUrl.String()+"?access_token="+s.AccessToken, nil)
	if err != nil {
		log.Printf("failed building request %s", err)
		return "", err
	}
	var resp *http.Response
	var client *http.Client
	// Temporarily adding insecure certificate bypass for testing
	allow_insecure := true
	if allow_insecure {
		tr := &http.Transport{
			TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
		}
		client = &http.Client{Transport: tr}
	} else {
		client = http.DefaultClient
	}
	resp, err = client.Do(req)
	if err != nil {
		log.Printf("%s %s %s", req.Method, req.URL, err)
		return "", err
	}
	body, err := ioutil.ReadAll(resp.Body)
	resp.Body.Close()
	log.Printf("%d %s %s %s", resp.StatusCode, req.Method, req.URL, body)
	if err != nil {
		log.Printf("%s %s %s", req.Method, req.URL, err)
		return "", err
	}
	if resp.StatusCode != 200 {
		log.Printf("%s %s %s", req.Method, req.URL, err)
		return "", err
	}
	json, err := simplejson.NewJson(body)
	if err != nil {
		log.Printf("%s %s %s", req.Method, req.URL, err)
		return "", err
	}
	//	json, err := api.Request(req)
	if err != nil {
		log.Printf("failed making request %s", err)
		return "", err
	}
	return json.Get("result").Get("primaryEmail").String()
}
开发者ID:xmosengineering,项目名称:dockerfiles,代码行数:47,代码来源:phabricator.go


示例12: ListTablesCallbackIterator

func (s *Server) ListTablesCallbackIterator(cb func(string)) error {
	var lastEvaluatedTableName string

	for {
		query := NewEmptyQuery()
		query.AddExclusiveStartTableName(lastEvaluatedTableName)

		jsonResponse, err := s.queryServer(target("ListTables"), query)
		if err != nil {
			return err
		}

		json, err := simplejson.NewJson(jsonResponse)
		if err != nil {
			return err
		}

		lastEvaluatedTableName = ""
		if json, ok := json.CheckGet("LastEvaluatedTableName"); ok {
			lastEvaluatedTableName, err = json.String()
			if err != nil {
				message := fmt.Sprintf("Unexpected response %s", jsonResponse)
				return errors.New(message)
			}
		}

		response, err := json.Get("TableNames").Array()
		if err != nil {
			message := fmt.Sprintf("Unexpected response %s", jsonResponse)
			return errors.New(message)
		}

		for _, value := range response {
			if t, ok := (value).(string); ok {
				cb(t)
			}
		}
		if lastEvaluatedTableName == "" {
			break
		}
	}

	return nil

}
开发者ID:docker,项目名称:goamz,代码行数:45,代码来源:table.go


示例13: DeleteTable

func (s *Server) DeleteTable(tableDescription TableDescriptionT) (string, error) {
	query := NewEmptyQuery()
	query.AddDeleteRequestTable(tableDescription)

	jsonResponse, err := s.queryServer(target("DeleteTable"), query)

	if err != nil {
		return "unknown", err
	}

	json, err := simplejson.NewJson(jsonResponse)

	if err != nil {
		return "unknown", err
	}

	return json.Get("TableDescription").Get("TableStatus").MustString(), nil
}
开发者ID:docker,项目名称:goamz,代码行数:18,代码来源:table.go


示例14: GetShardIterator

func (s *Server) GetShardIterator(streamArn, shardId, shardIteratorType, sequenceNumber string) (string, error) {
	query := NewEmptyQuery()
	query.AddStreamArn(streamArn)
	query.AddShardId(shardId)
	query.AddShardIteratorType(shardIteratorType)

	if len(sequenceNumber) != 0 {
		query.AddSequenceNumber(sequenceNumber)
	}

	jsonResponse, err := s.queryServer(streamsTarget("GetShardIterator"), query)

	if err != nil {
		return "unknown", err
	}

	json, err := simplejson.NewJson(jsonResponse)

	if err != nil {
		return "unknown", err
	}

	return json.Get("ShardIterator").MustString(), nil
}
开发者ID:PuerkitoBio,项目名称:goamz,代码行数:24,代码来源:stream.go


示例15: main

func main() {
	_, err := os.Stat("log")
	if err != nil {
		os.Mkdir("log", os.ModePerm)
	}

	if _, err := os.Stat("log/master.log"); err == nil {
		os.Remove("log/master.log")
	}

	log.WriteToFile("log/master.log")

	defer func() {
		if e := recover(); e != nil {
			log.LogFatalf(e)
			time.Sleep(1 * time.Second)
		}
	}()

	flag.Parse()
	if *config == "" {
		flag.PrintDefaults()
		return
	}

	m := master.NewMaster()
	apps := *config + "/app.json"
	appdata, e := ioutil.ReadFile(apps)
	if e != nil {
		panic(e)
	}

	var app master.App
	if err := json.Unmarshal(appdata, &app); err != nil {
		panic(err)
	}

	m.AppDef = app
	servers := *config + "/servers.json"
	json, err := readConfig(servers)
	if err != nil {
		panic(err)
	}

	def, err1 := json.Map()
	if err1 != nil {
		panic(err1)
	}
	for key := range def {
		if key == "master" {
			mst := json.Get(key)
			if host, ok := mst.CheckGet("host"); ok {
				v, err := host.String()
				if err != nil {
					panic(err)
				}

				m.Host = v
			} else {
				m.Host = "127.0.0.1"
			}

			if localip, ok := mst.CheckGet("localip"); ok {
				v, err := localip.String()
				if err != nil {
					panic(err)
				}

				m.LocalIP = v
			} else {
				m.LocalIP = "127.0.0.1"
			}

			if outerip, ok := mst.CheckGet("outerip"); ok {
				v, err := outerip.String()
				if err != nil {
					panic(err)
				}

				m.OuterIP = v
			} else {
				m.OuterIP = "127.0.0.1"
			}

			if port, ok := mst.CheckGet("port"); ok {
				v, err := port.Int()
				if err != nil {
					panic(err)
				}

				m.Port = v
			} else {
				m.Port = 5100
			}

			if agent, ok := mst.CheckGet("agent"); ok {
				v, err := agent.Bool()
				if err != nil {
					panic(err)
				}
//.........这里部分代码省略.........
开发者ID:mysll,项目名称:flynet,代码行数:101,代码来源:master.go



注:本文中的encoding/json.Get函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang json.HTMLEscape函数代码示例发布时间:2022-05-24
下一篇:
Golang json.Compact函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap