当前位置: 首页>>代码示例>>Golang>>正文


Golang json.NewDecoder函数代码示例

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


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

示例1: ExampleDecoder

// This example uses a Decoder to decode a stream of distinct JSON values.
func ExampleDecoder() {
	const jsonStream = `
		{"Name": "Ed", "Text": "Knock knock."}
		{"Name": "Sam", "Text": "Who's there?"}
		{"Name": "Ed", "Text": "Go fmt."}
		{"Name": "Sam", "Text": "Go fmt who?"}
		{"Name": "Ed", "Text": "Go fmt yourself!"}
	`
	type Message struct {
		Name, Text string
	}
	dec := json.NewDecoder(strings.NewReader(jsonStream))
	for {
		var m Message
		if err := dec.Decode(&m); err == io.EOF {
			break
		} else if err != nil {
			log.Fatal(err)
		}
		fmt.Printf("%s: %s\n", m.Name, m.Text)
	}
	// Output:
	// Ed: Knock knock.
	// Sam: Who's there?
	// Ed: Go fmt.
	// Sam: Go fmt who?
	// Ed: Go fmt yourself!
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:29,代码来源:example_test.go

示例2: DecodeJSON

func (self *DefaultJSONContext) DecodeJSON(i interface{}) error {
	buf := &bytes.Buffer{}
	bodyReader := io.TeeReader(self.Req().Body, buf)
	err := json.NewDecoder(bodyReader).Decode(i)
	if err != nil {
		return err
	}
	self.decodedBody = buf.Bytes()

	// skip checking errors since it can be an unsupported type
	_ = trimmer.TrimStrings(i)

	return nil
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:14,代码来源:context.go

示例3: GetSoundZones

func GetSoundZones(c ServiceConnector, account_id key.Key, token AccessToken) (result RemoteSoundZones, err error) {
	request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("accounts/%v/sound_zones", account_id.Encode()), token, nil)
	if err != nil {
		return
	}
	if response.StatusCode != 200 {
		err = errorFor(request, response)
		return
	}

	result = RemoteSoundZones{}
	err = json.NewDecoder(response.Body).Decode(&result)
	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:14,代码来源:client.go

示例4: GetSpotifyAccount

func GetSpotifyAccount(c ServiceConnector, soundZone key.Key, token AccessToken) (result *RemoteSpotifyAccount, err error) {
	request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("sound_zones/%v/spotify_account", soundZone.Encode()), token, nil)
	if err != nil {
		return
	}
	if response.StatusCode != 200 {
		err = errorFor(request, response)
		return
	}

	result = &RemoteSpotifyAccount{}
	err = json.NewDecoder(response.Body).Decode(result)
	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:14,代码来源:client.go

示例5: GetSpotifyAccounts

func GetSpotifyAccounts(c ServiceConnector, account key.Key, token AccessToken) (result RemoteSpotifyAccounts, err error) {
	request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("accounts/%v/payment_method/spotify_accounts", account.Encode()), token, nil)
	if err != nil {
		return
	}
	if response.StatusCode != 200 {
		err = errorFor(request, response)
		return
	}

	result = RemoteSpotifyAccounts{}
	err = json.NewDecoder(response.Body).Decode(&result)
	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:14,代码来源:client.go

示例6: GetAccounts

func GetAccounts(c ServiceConnector, user key.Key, token AccessToken) (result []RemoteAccount, err error) {
	request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("users/%v/accounts", user.Encode()), token, nil)
	if err != nil {
		return
	}
	if response.StatusCode != 200 {
		err = errorFor(request, response)
		return
	}

	result = []RemoteAccount{}
	err = json.NewDecoder(response.Body).Decode(&result)
	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:14,代码来源:client.go

示例7: GetPendingByExternalId

func GetPendingByExternalId(c ServiceConnector, externalId string, token AccessToken) (result *RemotePending, err error) {
	request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("pending/%v", externalId), token, nil)
	if err != nil {
		return
	}
	if response.StatusCode != 200 {
		err = errorFor(request, response)
		return
	}

	result = &RemotePending{}
	err = json.NewDecoder(response.Body).Decode(&result)
	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:14,代码来源:client.go

示例8: UpdateSoundZone

func UpdateSoundZone(c ServiceConnector, token AccessToken, updatedSoundZone RemoteSoundZone) (result *RemoteSoundZone, err error) {
	request, response, err := DoRequest(c, "PUT", c.GetAuthService(), fmt.Sprintf("sound_zones/%v", updatedSoundZone.Id.Encode()), token, updatedSoundZone)
	if err != nil {
		return
	}
	if response.StatusCode != 200 {
		err = errorFor(request, response)
		return
	}

	result = &RemoteSoundZone{}
	err = json.NewDecoder(response.Body).Decode(result)
	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:14,代码来源:client.go

示例9: CreateBusinessAccount

func CreateBusinessAccount(c ServiceConnector, token AccessToken, account RemoteAccount, owner key.Key) (result *RemoteAccount, err error) {
	request, response, err := DoRequest(c, "POST", c.GetAuthService(), fmt.Sprintf("users/%v/accounts/business", owner.Encode()), token, account)
	if err != nil {
		return
	}
	if response.StatusCode != 201 {
		err = errorFor(request, response)
		return
	}

	result = &RemoteAccount{}
	err = json.NewDecoder(response.Body).Decode(result)

	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:15,代码来源:client.go

示例10: GetAccountContact

func GetAccountContact(c ServiceConnector, account key.Key, token AccessToken) (result *RemoteUser, err error) {
	request, response, err := DoRequest(c, "GET", c.GetAuthService(), fmt.Sprintf("accounts/%v/contact", account.Encode()), token, nil)
	if err != nil {
		return
	}
	if response.StatusCode != 200 {
		err = errorFor(request, response)
		return
	}

	result = &RemoteUser{}
	err = json.NewDecoder(response.Body).Decode(result)

	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:15,代码来源:client.go

示例11: CreateLocation

func CreateLocation(c ServiceConnector, token AccessToken, remoteLocation RemoteLocation) (result *RemoteLocation, err error) {
	request, response, err := DoRequest(c, "POST", c.GetAuthService(), fmt.Sprintf("accounts/%v/locations", remoteLocation.Account.Encode()), token, remoteLocation)
	if err != nil {
		return
	}
	if response.StatusCode != 201 {
		err = errorFor(request, response)
		return
	}

	result = &RemoteLocation{}
	err = json.NewDecoder(response.Body).Decode(result)

	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:15,代码来源:client.go

示例12: GetBillingGroupsByAccountId

func GetBillingGroupsByAccountId(c ServiceConnector, account key.Key, token AccessToken) (result RemoteBillingGroups, err error) {
	request, response, err := DoRequest(c, "GET", c.GetPaymentService(), fmt.Sprintf("accounts/%v/billing_groups", account.Encode()), token, nil)
	if err != nil {
		return
	}
	if response.StatusCode != 200 {
		err = errorFor(request, response)
		return
	}

	result = RemoteBillingGroups{}
	err = json.NewDecoder(response.Body).Decode(&result)

	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:15,代码来源:client.go

示例13: UpdateUser

func UpdateUser(c ServiceConnector, user *RemoteUser, token AccessToken) (result *RemoteUser, err error) {
	request, response, err := DoRequest(c, "PUT", c.GetAuthService(), fmt.Sprintf("users/%v", user.Id.Encode()), token, user)
	if err != nil {
		return
	}
	if response.StatusCode != 200 {
		err = errorFor(request, response)
		return
	}

	result = &RemoteUser{}
	err = json.NewDecoder(response.Body).Decode(result)

	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:15,代码来源:client.go

示例14: CreateUser

func CreateUser(c ServiceConnector, user RemoteUser) (result *RemoteUser, err error) {
	request, response, err := DoRequest(c, "POST", c.GetAuthService(), "users", nil, user)
	if err != nil {
		return
	}
	if response.StatusCode != 201 {
		err = errorFor(request, response)
		return
	}

	result = &RemoteUser{}
	err = json.NewDecoder(response.Body).Decode(result)

	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:15,代码来源:client.go

示例15: CreateSlot

func CreateSlot(c ServiceConnector, token AccessToken, slot RemoteSlot) (result *RemoteSlot, err error) {
	request, response, err := DoRequest(c, "POST", c.GetRadioService(), fmt.Sprintf("schedules/%v/slots", slot.Schedule.Encode()), token, slot)
	if err != nil {
		return
	}
	if response.StatusCode != 201 {
		err = errorFor(request, response)
		return
	}

	result = &RemoteSlot{}
	err = json.NewDecoder(response.Body).Decode(result)

	return
}
开发者ID:DaviWei,项目名称:utils-1,代码行数:15,代码来源:client.go


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