How to parse 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 dynamic
June 10th 19 at 14:44
1 answer
June 10th 19 at 14:46
Solution
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"`
}

Well, using something like this.
var myData MyStruct

res, err := client.Get(uri)

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


Yes, try on funds,funds_incl_orders put everything there, or just those that need it.
@0xcffaedfe
Thank you very much!
But
There will be more ~300 values only in 1 dynamic field.
They also need to bring - cayla.Rippin commented on June 10th 19 at 14:49
Oh Yes there is because the currencies pull the list from the website of the business then. - Frida15 commented on June 10th 19 at 14:52
another question
Usd float64 `json:"usd"`

fmt.Printf("Balance: %v", data.Return.Funds.Usd)

Displays
Balance: 2.46 e-06

And it should be 0.00000246 - cayla.Rippin commented on June 10th 19 at 14:55
well blah -> "%v"

https://golang.org/pkg/fmt/ <- docks - Frida15 commented on June 10th 19 at 14:58

Find more questions by tags Go