从 API 中读取 JSON VB.NET 中没有 Class 的响应
Read JSON from API Response without Class in VB.NET
所以,我正在从 WordPress API 阅读 JSON,然后阅读内容。 JSON WP API returns 是这样的字典列表:
[
{
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/",
}
]
我试着这样读:
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")
但它不起作用。我想遍历 API 中的所有数据。到目前为止我看到的所有例子都非常复杂。我可以在不使用 class 的情况下执行此操作吗?谢谢
您在 json 中有一个数组,所以使用此代码
Dim json As JArray = JArray.Parse(result)
link_status.Text = json(0).SelectToken("id");
所以,我正在从 WordPress API 阅读 JSON,然后阅读内容。 JSON WP API returns 是这样的字典列表:
[
{
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/",
}
]
我试着这样读:
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")
但它不起作用。我想遍历 API 中的所有数据。到目前为止我看到的所有例子都非常复杂。我可以在不使用 class 的情况下执行此操作吗?谢谢
您在 json 中有一个数组,所以使用此代码
Dim json As JArray = JArray.Parse(result)
link_status.Text = json(0).SelectToken("id");