使用 json2.asp KEY 值解析 JSON 字符串

Parsing JSON String with json2.asp KEY Values

我正在尝试解析这个 JSON 字符串 -

{
   "Success": true,
   "Messages": [],
   "LeadInfo": {
      "LeadID": "21941873",
      "CapturedDate": "4/29/2015 9:39:33 AM",
      "CapturedBy": "Dev Kit 15231929",
      "ConnectKey": "1001",
      "FirstName": "DEMO_1001",
      "LastName": "ATTENDEE_1001",
      "Title": "",
      "Company": "DEMOCOMPANY_1001",
      "Company2": "",
      "Address": "145861 N Market Street",
      "Address2": "",
      "Address3": "",
      "City": "Frederick",
      "StateCode": "MD",
      "ZipCode": "21701",
      "CountryCode": "United States",
      "Email": "1001@experient-inc.com",
      "Phone": "1234567890",
      "PhoneExtension": "1111",
      "Fax": "9876543210",
      "Notes": ""
   },
   "Demographics": [
      {
         "Key": "CATEGORY",
         "Description": "Category/Classification",
         "Value": "Educator"
      },
      {
         "Key": "SPECIALTY",
         "Description": "Specialty",
         "Value": "General"
      },
      {
         "Key": "ADDTYPECODE",
         "Description": "ADDRESS TYPE",
         "Value": ""
      }
   ]
}

我可以使用这个获取所有值 -

Dim Att: Set Att = JSON.parse(API_Response)

Att.LeadInfo.get("FirstName")
Att.LeadInfo.get("LastName")

效果很好。

我的问题是如何获取人口统计数据中的值。我想要获得的是 CATEGORY KEY 的值 "Educator"。

有什么想法吗?

Demographics 对象似乎是一个对象数组。您应该能够使用 For Each 循环依次枚举对象并检查特定的 Key.

Dim demo, key, desc, val
'...
For Each demo In Att.Demographics
  key = demo.Get("Key")
  desc = demo.Get("Description")
  val = demo.Get("Value")
  If key = "CATEGORY" Then Exit For
Next

... - 表示假定代码