正确格式化“ For Each”以与JSON结合使用

时间:2019-11-15 23:44:41

标签: json for-loop

我正在VB.NET中编码。我需要阅读JSON的帮助。这是原始的JSON数据:

{
  "status": 200,
  "likelihood": 2,
  "data": {
    "emails": [
      {
        "address": "none@hotmail.com",
        "type": "personal",
        "sha256": "53ec4387bf9f1e3ff62458000d3203518d1ed08d8de49bdd3493099befed7822",
        "domain": "hotmail.com",
        "local": "none"
      }
    ],

好的,现在为了让我阅读电子邮件数组,我需要这样做:

        Dim read = Newtonsoft.Json.Linq.JObject.Parse(GlobalVariables.MostRecentSearch)
        For Each read.Item("data")("emails") As string
            TextBox4.Text = read.Item("data")("emails")(0)("address").ToString
        Next

但是很明显,我的For Each陈述是错误的。在上面的代码中索引显示为(0),并且我想循环浏览所有潜在的电子邮件地址(计数未知),该怎么做?

谢谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我知道了。这是For Each语句的正确格式:

                Dim emails As String
                emails = ""
                For Each email As Newtonsoft.Json.Linq.JObject In read.Item("data")("emails")
                    emails = emails & email.Item("address").ToString & ","
                Next