@gachkydxvbgd

Как распарсить resp.Body json?

{
	"success":1,
	"return":{
		"funds":{
			"ltc":22,
			"nvc":423.998,
			"ppc":10,
			...
		},
		"funds_incl_orders":{
			"ltc":32,
			"nvc":523.998,
			"ppc":20,
			...
		},	
		"rights":{
			"info":1,
			"trade":0,
			"withdraw":0
		},
		"transaction_count":0,
		"open_orders":1,
		"server_time":1418654530
	}
}

funds,funds_incl_orders динамичные
  • Вопрос задан
  • 222 просмотра
Решения вопроса 1
0xcffaedfe
@0xcffaedfe
Developer & Reverser
package MyDataParser

import (
  "encoding/json"
  "io"
)

type Parser interface {
  DecodeJSON(r io.Reader) error
}

func (p *MyStruct) DecodeJSON(r io.Reader) error {
  return json.NewDecoder(r).Decode(&p)
}

type MyStruct struct {
  Success int `json:"success"`
  Return  struct {
    Funds struct {
      Ltc int     `json:"ltc"`
      Nvc float64 `json:"nvc"`
      Ppc int     `json:"ppc"`
    } `json:"funds"`
    FundsInclOrders struct {
      Ltc int     `json:"ltc"`
      Nvc float64 `json:"nvc"`
      Ppc int     `json:"ppc"`
    } `json:"funds_incl_orders"`
    Rights struct {
      Info     int `json:"info"`
      Trade    int `json:"trade"`
      Withdraw int `json:"withdraw"`
    } `json:"rights"`
    TransactionCount int `json:"transaction_count"`
    OpenOrders       int `json:"open_orders"`
    ServerTime       int `json:"server_time"`
  } `json:"return"`
}

Ну юзать как-то вот так.
var myData MyStruct

res, err := client.Get(uri)

err = posts.DecodeJSON(res.Body)
,,,


Да побую на funds,funds_incl_orders впиши все возможные, либо только те что нужны.
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы