Announcement

Collapse
No announcement yet.

CURL n00b pollen.com results

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Originally posted by prsmith777 View Post
    I'm interested in pulling the allergens from the JSON data. It seems sometimes there are three allergens and sometimes two or even one allergen.

    I'm a complete novice when it comes to JSON. I managed to get these lines of code to pull the data when there are three allergens, but when there are less I get an error.

    Any help would be appreciated.
    I typically check for nulls when doing json parsing:

    Code:
    Dim pollenTrigger0 as String
    If Not isNothing(jsonData("Location")("periods")("1")("Triggers")("0")("Name")) Then pollenTrigger0 = jsonData("Location")("periods")("1")("Triggers")("0")("Name")
    HS 3.0.0.548: 1976 Devices 1156 Events
    Z-Wave 3.0.1.262: 123 Nodes on one Z-Net

    Comment


    • #17
      Thanks sparkman, I should be able to get it to work with this.

      Comment


      • #18
        Code:
        For i As Integer = 0 To 2
          If i <= UBound(jsonData("Location")("periods")("1")("Triggers")) Then
            allergenName = jsonData("Location")("periods")("1")("Triggers")(Cstr(i))("Name")
            allergenType = jsonData("Location")("periods")("1")("Triggers")(Cstr(i))("PlantType")
            allergenTypeValue = 0
            Select Case allergenType
              Case "Tree"
                allergenTypeValue = 1
              Case "Grass"
                allergenTypeValue = 2
              Case "Ragweed"
                allergenTypeValue = 3
            End Select
            html = "<img src=""/images/Pollen/" & allergenType & ".png""  height=""32""> " & allergenName
            hs.SetDeviceString(devID, html, True)
          Else
            hs.SetDeviceString(devID, "", True)
          End If
        Next
        So this is a snippet of what I use. I have 3 devices since the maximum number of "Triggers" or allergens is 3.
        There are 3 different plant types: Tree, Grass and Ragweed.
        When the API result only has 2 "Triggers" or allergens, I want to leave the 3rd device empty, hence a 3x loop.
        The Ubound function will tell me how many "Triggers" or allergens there are in total in the JSON so I don't do a null check.
        I set the device string to include the name of allergen and an image. Works well with HSTouch.

        I attached the images I use for the img src. I converted the SVG on the Pollen website to PNG.

        Hope this helps.

        Comment


        • #19
          Thanks HS14. This is awesome.

          Comment


          • #20
            Originally posted by prsmith777 View Post
            Thanks HS14. This is awesome.
            My pleasure.

            Comment

            Working...
            X