У меня есть следующие json для работы:
jsonStr := `{"Ok":[true,{"amount_awaiting_confirmation":"0","amount_awaiting_finalization":"0","amount_currently_spendable":"0","amount_immature":"0","amount_locked":"0","last_confirmed_height":"551632","minimum_confirmations":"10","total":"0"}]}`
Вот как я справляюсь сейчас:
resMap := make(map[string]interface{}, 0)
json.Unmarshal([]byte(jsonStr), &resMap)
if val, ok := resMap["Ok"]; ok {
tup := val.([]interface{})
wMap := tup[1].(map[string]interface{})
amountAwaitingConfirmation, _ := strconv.ParseInt(wMap["amount_awaiting_confirmation"].(string), 10, 64)
amountAwaitingFinalization, _ := strconv.ParseInt(wMap["amount_awaiting_finalization"].(string), 10, 64)
amountCurrentSpendable, _ := strconv.ParseInt(wMap["amount_currently_spendable"].(string), 10, 64)
amountImmature, _ := strconv.ParseInt(wMap["amount_immature"].(string), 10, 64)
amountLocked, _ := strconv.ParseInt(wMap["amount_locked"].(string), 10, 64)
lastConfirmedHeight, _ := strconv.ParseInt(wMap["last_confirmed_height"].(string), 10, 64)
minimumConfirmations, _ := strconv.ParseInt(wMap["minimum_confirmations"].(string), 10, 64)
total, _ := strconv.ParseInt(wMap["total"].(string), 10, 64)
}
Есть ли более простой способ справиться эта структура без необходимости прибегать к обобщению c interface {}?