So, I am reading JSON from WordPress API and then read the contetnts. The JSON WP API returns is a list of dictionaries like this:
[
{
id: 8484,
date: "2022-03-12T21:00:00",
date_gmt: "2022-03-12T15:30:00",
modified: "2022-03-12T17:35:35",
modified_gmt: "2022-03-12T12:05:35",
slug: "5-ways-to-increase-leads-for-solar-companies",
status: "publish",
type: "post",
link: "https://inklik.com/blog/5-ways-to-increase-leads-for-solar-companies/",
},
{
id: 8484,
date: "2022-03-12T21:00:00",
date_gmt: "2022-03-12T15:30:00",
modified: "2022-03-12T17:35:35",
modified_gmt: "2022-03-12T12:05:35",
slug: "5-ways-to-increase-leads-for-solar-companies",
status: "publish",
type: "post",
link: "https://inklik.com/blog/5-ways-to-increase-leads-for-solar-companies/",
},
{
id: 8484,
date: "2022-03-12T21:00:00",
date_gmt: "2022-03-12T15:30:00",
modified: "2022-03-12T17:35:35",
modified_gmt: "2022-03-12T12:05:35",
slug: "5-ways-to-increase-leads-for-solar-companies",
status: "publish",
type: "post",
link: "https://inklik.com/blog/5-ways-to-increase-leads-for-solar-companies/",
}
]
I tried reading it like this:
Dim webClient As New System.Net.WebClient
Dim result As String = webClient.DownloadString("https://www." domain.Text() "/wp-json/wp/v2/posts/")
Dim json As JObject = JObject.Parse(result)
link_status.Text = json.SelectToken(0).SelectToken("id")
But it is not working. I want to iterate through all the data in the API. All the examples I have seen so far are very complicated. Can I do this without using a class? Thanks
CodePudding user response:
you have an array in json, so use this code
Dim json As JArray = JArray.Parse(result)
link_status.Text = json(0).SelectToken("id");