1

Is there such an answer in json format

{
    "id": "161e6e624c78acfd7fd783844bc0adfa38c5135feb9170c9e8a05094ac41f11a1d87552aae3cd6544cecf7f3b8162edee7c01f5785c14f5ed11e1eee14e28619",
    "name": "Geth/genom.minerpool.net/v1.8.0-unstable-8ec3861d/linux-amd64/go1.9.2",
    "caps": [
      "eth/62",
      "eth/63"
    ],
    "network": {
      "localAddress": "192.168.1.3:8298",
      "remoteAddress": "213.32.53.162:31337"
    },
    "protocols": {
      "eth": {
        "version": 63,
        "difficulty": 121712103143555595,
        "head": "0x7686acff7fa7560013bb6c7997c42d7f6adb0514277edbb7418e362b8e32bca2"
      }
    }
  },

The code of the program that is desalting the request.

public class per 
{
    //[JsonProperty("network")]
    public string localAddress { get; set; }
    public string id { get; set; }
    public string name { get; set; }
}

private void button2_Click(object sender, EventArgs e)
{
    var peer = JsonConvert.DeserializeObject<List<per>>(richTextBox1.Text.ToString());
    dataGridView2.DataSource = peers.Result;
}

The problem is that it does not put a blank field in the datagridview of localAddres. What am I doing wrong?

Aleks Andreev
  • 7,016
  • 8
  • 29
  • 37
Gy9vin
  • 13
  • 2
  • 2
    Your classes do not reflect your JSON, see [How to auto-generate a C# class file from a JSON object string](https://stackoverflow.com/q/21611674) to generate correct classes automatically. – dbc May 29 '18 at 17:39

1 Answers1

0

The JSON is being deserialized to a collect while it is a single object.

Using the classes defined in the other answer, the event handler should be done as follows.

private async void button2_Click(object sender, EventArgs e) {
    var enbode = new Nethereum.Geth.Web3Geth("http://127.0.0.1:8545");
    var peers = await enbode.Admin.Peers.SendRequestAsync();
    richTextBox1.Text = peers.ToString();
    var peer = JsonConvert.DeserializeObject<Example>(richTextBox1.Text);
    dataGridView2.DataSource = new [] { peer };
}
Nkosi
  • 235,767
  • 35
  • 427
  • 472