Retrieve various elements from an array in a JSON file using vb.NET and then connect them to a datatable

I'm in the process of developing a vb.net win form that utilizes a URL to fetch a json file which I need to insert into a datatable. I'm facing a challenge with organizing my public class hierarchy without ending up with too many lines of code. Currently, I am attempting to dump all the information into a textbox but eventually plan to transfer it into a datatable for display on a datagridview. Here's a glimpse of the json file and the corresponding URL:

URL:

Snippet from the json file:

{
    "status": "ok",
    "meta": {
        "count": 632,
        "page_total": 7,
        "total": 632,
        "limit": 100,
        "page": null
    },
    "data": {
        ...

The issue lies in the structure of the "data" section where there are multiple subfields like 1, 33, 49, etc. Creating a public class for each of these numbers seems inefficient. I seek guidance on how to list the attributes tier, name, and tank_id into a datatable efficiently.

My current vb.net code:

Imports System.Net
...

--------------------


I've attempted to handle this by serializing and deserializing the json result but encountered issues due to non-sequential id numbers. Any assistance would be greatly appreciated.

Dim tokenjson = JsonConvert.SerializeObject(uri1)
...

Thank you,

Answer №1

You didn't provide specific instructions on how you wanted the data, so I decided to display it in a textbox.

Imports Newtonsoft.Json.Linq

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim URL As String = "https://api.worldoftanks.com/wot/encyclopedia/vehicles/?application_id=c2b5cb8d6c77098c8a9a481e68476b28&fields=short_name%2C+tank_id%2C+tier"
        Dim ParseJSON As JObject = JObject.Parse(New Net.WebClient().DownloadString(URL))

        For Each tank As JProperty In ParseJSON("data")
            Dim LineHolder As String = Nothing
            For Each tankinfo As JProperty In tank.First
                LineHolder &= String.Format("{0}: {1}, ", tankinfo.Name, tankinfo.Value)
            Next
            LineHolder = LineHolder.Remove(LineHolder.Length - 2)
            TextBox2.AppendText(LineHolder & Environment.NewLine)
        Next
    End Sub

https://i.sstatic.net/cCuXT.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What are some strategies for debugging a live Angular2/Typescript application?

As I start the exciting journey of creating a new app with Angular2 and Typescript, two technologies that I have never used together before (although I do have experience using them individually), a question arises in my mind. How can I effectively debug ...

Is there a way to divide a string using multiple separators that function as a single separator in JavaScript?

Searching for a way to split a string into an array using "space and the comma" (" ,") as the separator, I came across similar questions but couldn't find a solution that fulfills my requirements. I want both space and comma to work ONLY as one separa ...

Jackson does not seem to be registering the @JsonCreator annotation

I am currently working with Jackson 1.4.2 and facing an issue while trying to deserialize unique identifier values (referred to as `code`) that are sent from our UI to Java controllers (Servlets). We have various types (such as `ABCType`, `XYZType`, etc.) ...

Utilize the Material UI feature to call the function

How can I pass a function as a prop to my Material UI component if the function is undefined within the component? import React, { Component } from 'react'; import styled from 'styled-components'; import InputBase from '@material- ...

Storing JSON Data with Null Values in a Delta Lake Table Using PySpark

I am facing an issue while attempting to save JSON data as a Delta Lake table using PySpark and Delta Lake. Below is the code snippet: from pyspark.sql import SparkSession from pyspark.sql.types import StructType, StructField, StringType, IntegerType from ...

Using Angular.js to Implement Filtering with Intervals

I have implemented a unique custom angular.js filter for formatting datetime objects: function relativeTimeFilter() { return function (dateObj) { return getRelativeDateTimeString(dateObj); }; } function getRelativeDateTimeString(dt) { ...

Encoding identification data from JSON using ColdFusion

Hello everyone, I've been puzzling over how to intercept and encrypt database record ID from a JSON request in ColdFusion. Below is the code I have so far, along with my unsuccessful attempt. Any assistance would be greatly appreciated. <cfquery ...

Issue with JQuery functionality when included in a separate .js file

My JQuery code is causing me some trouble. Interestingly, when I embed this code within script tags directly in my HTML file, everything works fine. But as soon as I try to place it in a separate JavaScript file, it simply refuses to work. And no, the iss ...

Is combining Passport.js Google authentication with JWT a logical choice?

I am currently working on integrating Google Login with Passport.js into my MERN stack application. However, I have created this middleware for JWT authentication: const jwt = require("jsonwebtoken"); const config = require("config"); module.exports = a ...

Expanding the dimensions of $state.store.object within a vue.js application

As I delve into learning Vue.js, I've noticed that the application I'm currently developing fetches data from a database and then organizes it into a list before binding and displaying it on the page. Here's a snippet of the code where this ...

Tips for aligning the first element in an inline-block list item horizontally

I'm working on a list with horizontal scroll functionality to allow users to view content by scrolling. I have successfully implemented this, but I'm facing a couple of challenges that I need help with: I want the first item in the list to alwa ...

Executing various actions on a single route by utilizing request type in Zend Framework 2

Looking to implement ZF2 RESTful responses for various request types. In my module.config.php, the router configuration looks like this: 'router' => array( 'routes' => array( 'student' => array( ...

What methods can I employ to intentionally trigger a mongodb error in order to evaluate the try and catch condition using jest?

Testing my code is essential, but I want to ensure that any errors are caught and handled properly. This is achieved by structuring my code in a way that prevents it from reaching the catch condition. This is made possible by using a throw condition for t ...

One method to retrieve the id from the database when the button is clicked using ajax

In this particular scenario, I am working on a message thread that is inside a modal. The objective is to display a message thread for a specific individual based on their reference number. However, I am encountering an issue in passing the reference numbe ...

Error message in Fb Messenger: Quick replies data is not valid

I encountered the following error: { message: '(#100) Invalid data', type: 'OAuthException', code: 100, error_subcode: 2018032, fbtrace_id: 'H3qnFWWxE9u' } } while attempting to send this to Facebook m ...

gridview Error: Object reference is not assigned to an object instance

I am encountering an error only when my web app is published, not when I run it locally. I am using Visual Studio 2010. The error occurs on this line of code: Dim money As String = footer.Cells(1).Text.Replace("£", String.Empty) The purpose of this co ...

In Rails, assigning unique IDs to elements in the builder allows for easy access with jQuery

Utilizing the Rails builder to construct multiple :pay objects <%= f.fields_for :pay do |builder| %> <%= render "non_taxable_pays", :f => builder %> <% end %> This is displaying _taxable_pays multip ...

Issue with adding JSON data to file - encountering a problem where only 'Object Object'

I have been attempting to add a new data node to a JSON file through my JavaScript code: var newDate = new Date; var markerId = newDate.getTime(); var markerData = { 'id': markerId, 'lat':markerId, ...

Making Jquery functions work with Internet Explorer (including toggle and animate)

Why is this jQuery code snippet not functioning as expected in Internet Explorer? It works flawlessly across all Webkit browsers. $('#logo').toggle(function() { $('#about').animate({'top': '-400px'},'slow&a ...

How to retrieve multiple checked values from checkboxes in Semantic UI React

Trying to enable users to select multiple checkboxes in react using semantic-ui-react. I am new to react. Here is my code: class ListHandOver extends React.Component { state = { data: {} } handleChange = (e, data) => { console.log( ...