How to make a class that fits Blockchain info Json

0 votes

I'm using Blockchain.info API. I want to deserialize the JSON response. An example response:

{
    "addresses": [
        {
            "balance": 1400938800,
            "address": "1Q1AtvCyKhtveGm3187mgNRh5YcukUWjQC",
            "label": "SMS Deposits",
            "total_received": 5954572400
        },
        {
            "balance": 79434360,
            "address": "1A8JiWcwvpY7tAopUkSnGuEYHmzGYfZPiq",
            "label": "My Wallet",
            "total_received": 453300048335
        },
        {
            "balance": 0,
            "address": "17p49XUC2fw4Fn53WjZqYAm4APKqhNPEkY",
            "total_received": 0
        }
    ]
}

I want to know how to make a class that fits this. I tried this but it's not working:

Public Function LoadJson(ByVal json As String)
    Dim items As List(Of addresses) = JsonConvert.DeserializeObject(Of List(Of addresses))(json)
    Return items
End Function
Public Class addresses
    Public addresses As address()
End Class
Public Class address
    Public balance
    Public address
    Public label
    Public total_received
End Class
Sep 18, 2018 in Blockchain by slayer
• 29,370 points
1,559 views

1 answer to this question.

0 votes

Hey, I found a simple solution for this:

Go to this link: http://json2csharp.com/ paste your json and it will make your class and its dependency.

Now, you may create your new one in your app and the use simply javascript.serialize,deserialize nothing else and it will work perfectly

Here is a console application example working perfectly:

Imports System.Net
Imports System.IO
Imports System.Configuration
Imports System.Web.Script.Serialization

Module Module1
    Dim js As New JavaScriptSerializer

    Sub Main()

    Dim json As String = String.Empty

    Using sr As New StreamReader("C:\Users\Giorgio\Desktop\GOOGLEDRIVE\hpc\PROGETTI VS PERSONALI\VISUALSTUDIOPROJECT\2014\Smples\Smples\json.txt")
        json = sr.ReadToEnd
    End Using
    Dim separator As String = "**********************************************************"
    Dim root As RootObject = js.Deserialize(Of RootObject)(json)

    For Each el In root.addresses
        Console.WriteLine(String.Format("{0}" & vbCrLf & "{1}" & vbCrLf & "{2}" & vbCrLf & "{3}" & vbCrLf & separator, el.address, el.balance, el.label, el.total_received))
    Next


        Console.ReadLine()
End Sub


Public Class Address
    Public Property balance() As Integer
        Get
            Return m_balance
        End Get
        Set(value As Integer)
            m_balance = Value
        End Set
    End Property
    Private m_balance As Integer
    Public Property address() As String
        Get
            Return m_address
        End Get
        Set(value As String)
            m_address = Value
        End Set
    End Property
    Private m_address As String
    Public Property label() As String
        Get
            Return m_label
        End Get
        Set(value As String)
            m_label = Value
        End Set
    End Property
    Private m_label As String
    Public Property total_received() As Object
        Get
            Return m_total_received
        End Get
        Set(value As Object)
            m_total_received = Value
        End Set
    End Property
    Private m_total_received As Object
End Class

Public Class RootObject
    Public Property addresses() As List(Of Address)
        Get
            Return m_addresses
        End Get
        Set(value As List(Of Address))
            m_addresses = Value
        End Set
    End Property
    Private m_addresses As List(Of Address)
End Class
End Module
answered Sep 18, 2018 by digger
• 26,740 points

Related Questions In Blockchain

0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 1,567 views
+1 vote
1 answer

How does a miner get to know that a transaction is verified by all the nodes?

Contrary to the popular belief, it is ...READ MORE

answered Mar 27, 2018 in Blockchain by Johnathon
• 9,090 points
2,838 views
0 votes
1 answer

How to create a new wallet on a blockchain?

Firstly, you need to have a clear ...READ MORE

answered Apr 4, 2018 in Blockchain by Christine
• 15,790 points
1,382 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,219 views
0 votes
1 answer

How do I add multiple recipients for transactions via Blockchain API?

Convert the recipes into JSON objects. x = ...READ MORE

answered Jul 6, 2018 in Blockchain by Perry
• 17,100 points
885 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
0 votes
0 answers

Blockchain.info wallet API callback

I am implementing blockchain.info wallet api to ...READ MORE

Jul 4, 2018 in Blockchain by sabby
• 4,370 points
885 views
0 votes
1 answer

How to build a non-payment application using Ethereum blockchain?

I hope the following link is helpful ...READ MORE

answered Jul 17, 2018 in Blockchain by digger
• 26,740 points
657 views
0 votes
1 answer

How to connect a NS3 node to my local blockchain?

To connect all your nodes with all ...READ MORE

answered Jul 25, 2018 in Blockchain by digger
• 26,740 points
2,505 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP