Announcement

Collapse
No announcement yet.

json script help and advice

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

    json script help and advice

    Hi all,
    //SOLVED!!













    I changed my question and script and made it to understand better.
    My question is when i retrieve some data from json like here:

    Code:
    GFT = obj.Item("GFT").ToString.replace("""","").replace("[","").replace("]","")
    REST= obj.Item("REST").ToString.replace("""","").replace("[","").replace("]","")
    PAPIER = obj.Item("PAPIER").ToString.replace("""","").replace("[","").replace("]","")
    PMD = obj.Item("PMD").ToString.replace("""","").replace("[","").replace("]","")
    It returns like this :

    Code:
    Feb-14 10:16:31	 	PMD	04-01-2018, 01-02-2018, 01-03-2018, 02-08-2018
    Feb-14 10:16:31	 	PAPIER	02-01-2018, 30-01-2018, 06-03-2018, 03-04-2018, 01-05-2018, 05-06-2018, 03-07-2018, 07-08-2018, 04-09-2018, 02-10-2018, 30-10-2018, 27-11-2018
    Feb-14 10:16:31	 	REST	03-01-2018, 17-01-2018, 14-02-2018, 28-02-2018, 14-03-2018, 28-03-2018, 11-04-2018, 25-04-2018, 09-05-2018, 23-05-2018, 20-06-2018, 18-07-2018, 01-08-2018, 15-08-2018, 29-08-2018, 12-09-2018, 26-09-2018, 10-10-2018, 24-10-2018, 07-11-2018, 21-11-2018, 05-12-2018, 19-12-2018
    Feb-14 10:16:31	 	GFT	10-01-2018, 24-01-2018, 07-02-2018, 21-02-2018, 21-03-2018, 18-04-2018, 02-05-2018, 16-05-2018, 30-05-2018, 13-06-2018, 27-06-2018, 11-07-2018, 25-07-2018, 25-07-2018, 22-08-2018, 19-09-2018, 03-10-2018, 17-10-2018, 14-11-2018, 12-12-2018, 29-12-2018, 29-12-2018
    My question is how to let it check the data one by one with multiple array for GFT,REST,PAPIER,PMD ?
    Because now i get all the data at once and i can't compare with DateTime.Today

    regards



    regards
    Last edited by Malosa; February 17, 2018, 12:24 PM. Reason: SOLVED
    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




    HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

    #2
    I changed the question.
    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




    HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

    Comment


      #3
      Without the full context of what you are trying to achieve it's a little difficult to say what the best way would be but it looks like your data is returned as json arrays and there is probably a better way of dealing with it.

      Regarding your question. The following code would split one of your string examples on the , into an array and then look to see if any of the values in the array match.

      Paul..


      Code:
      Dim strPMD As String = "04-01-2018, 09-02-2018, 01-03-2018, 02-08-2018"
              Dim arrPMD() As String = strPMD.Split(",")
      
              Dim Found As Boolean = False
      
              For i = 0 To UBound(arrPMD)
                  If Trim(arrPMD(i)) = Date.Today.ToString("dd-MM-yyyy") Then
                      Found = True
                      Exit For
                  End If
              Next
      
              If Found Then
                  'Do something here
              End If

      Comment


        #4
        Thanks paul,

        but it didn't work.
        Today is a match but doesnt show up at found.

        Code:
        Dim SplitStr2() As String = rest.Split(",")
        
                Dim Found As Boolean = False
        
                For i = 0 To UBound(SplitStr2)
                    If Trim(SplitStr2(i)) = Date.Today.ToString("dd/MM/yyy") Then
                        Found = True
                        Exit For
                    End If
                Next
        
                If Found Then
                    hs.writelog ("ok","REST FOUND")
                End If
        i checked if Date.Today.ToString("dd/MM/yyy") is correct and it is correct... 14-02-2018 and the json data the same 14-02-2018


        But there is 1 thing, i have 2 devices tomorrow and today.
        if there is a match for today i set a virtual device text for today
        If there is a match for tomorrow i set a virtual device text for tomorrow
        and if there is no match for today but for tomorrow, i need to set text for both vise versa.


        i use this code in my script so i can see for today and tomorrow.
        Code:
         Dim StartDate As DateTime = DateTime.Today.AddDays(0) 'this will be today
         Dim FinishDate As DateTime = DateTime.Today.AddDays(1) 'this will be the end of tomorrow
        any idea ?





        Originally posted by sooty View Post
        Without the full context of what you are trying to achieve it's a little difficult to say what the best way would be but it looks like your data is returned as json arrays and there is probably a better way of dealing with it.

        Regarding your question. The following code would split one of your string examples on the , into an array and then look to see if any of the values in the array match.

        Paul..


        Code:
        Dim strPMD As String = "04-01-2018, 09-02-2018, 01-03-2018, 02-08-2018"
                Dim arrPMD() As String = strPMD.Split(",")
        
                Dim Found As Boolean = False
        
                For i = 0 To UBound(arrPMD)
                    If Trim(arrPMD(i)) = Date.Today.ToString("dd-MM-yyyy") Then
                        Found = True
                        Exit For
                    End If
                Next
        
                If Found Then
                    'Do something here
                End If
        Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
        Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




        HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

        Comment


          #5
          In your first example the date is shown with the format dd-MM-yyyy and in your code you are searching for format dd/MM/yyyy.

          If you change this line

          If Trim(SplitStr2(i)) = Date.Today.ToString("dd/MM/yyy") Then

          to

          If Trim(SplitStr2(i)) = Date.Today.ToString("dd-MM-yyy") Then

          does it then work?

          Paul..

          Comment


            #6
            The following should work for today and tomorrow.

            You could make a function and pass the (PMT, REST, GFT etc) in as a string if you always check for today / tomorrow.

            The return value could be an integer
            0 = None found
            1 = Today found
            2 = Tomorrow found
            3 = Both today and tomorrow found.

            Paul..

            Code:
              Dim strRest As String = "03-01-2018, 17-01-2018, 14-02-2018, 15-02-2018, 14-03-2018, 28-03-2018, 11-04-2018, 25-04-2018, 09-05-2018, 23-05-2018, 20-06-2018, 18-07-2018, 01-08-2018, 15-08-2018, 29-08-2018, 12-09-2018, 26-09-2018, 10-10-2018, 24-10-2018, 07-11-2018, 21-11-2018, 05-12-2018, 19-12-2018"
                    Dim arrRest() As String = strRest.Split(",")
            
                    Dim dToday As String = Today.ToString("dd-MM-yyy")
                    Dim dTomorow As String = Today.AddDays(1).ToString("dd-MM-yyy")
            
                    Dim boolFoundToday As Boolean = False
                    Dim boolFoundTomorrow As Boolean = False
            
                    For i = 0 To UBound(arrRest)
                        If Trim(arrRest(i)) = dToday Then
                            boolFoundToday = True
                        End If
            
                        If Trim(arrRest(i)) = dTomorow Then
                            boolFoundTomorrow = True
                        End If
                    Next
            
                    If boolFoundToday Then
                        hs.writelog("ok", "Found Today")
                    End If
            
                    If boolFoundTomorrow Then
                        hs.writelog("ok", "Found Tomorrow")
                    End If

            Comment


              #7
              Hi paul i did try , and it did not work


              I changed yours to Dim strRest As String = rest


              Output of REST
              Code:
              Feb-14 17:32:11	 	ok	03-01-2018, 17-01-2018, 14-02-2018, 28-02-2018, 14-03-2018, 28-03-2018, 11-04-2018, 25-04-2018, 09-05-2018, 23-05-2018, 20-06-2018, 18-07-2018, 01-08-2018, 15-08-2018, 29-08-2018, 12-09-2018, 26-09-2018, 10-10-2018, 24-10-2018, 07-11-2018, 21-11-2018, 05-12-2018, 19-12-2018
              With your manual dates it works but not with my REST

              regards


              Originally posted by sooty View Post
              The following should work for today and tomorrow.

              You could make a function and pass the (PMT, REST, GFT etc) in as a string if you always check for today / tomorrow.

              The return value could be an integer
              0 = None found
              1 = Today found
              2 = Tomorrow found
              3 = Both today and tomorrow found.

              Paul..

              Code:
                Dim strRest As String = "03-01-2018, 17-01-2018, 14-02-2018, 15-02-2018, 14-03-2018, 28-03-2018, 11-04-2018, 25-04-2018, 09-05-2018, 23-05-2018, 20-06-2018, 18-07-2018, 01-08-2018, 15-08-2018, 29-08-2018, 12-09-2018, 26-09-2018, 10-10-2018, 24-10-2018, 07-11-2018, 21-11-2018, 05-12-2018, 19-12-2018"
                      Dim arrRest() As String = strRest.Split(",")
              
                      Dim dToday As String = Today.ToString("dd-MM-yyy")
                      Dim dTomorow As String = Today.AddDays(1).ToString("dd-MM-yyy")
              
                      Dim boolFoundToday As Boolean = False
                      Dim boolFoundTomorrow As Boolean = False
              
                      For i = 0 To UBound(arrRest)
                          If Trim(arrRest(i)) = dToday Then
                              boolFoundToday = True
                          End If
              
                          If Trim(arrRest(i)) = dTomorow Then
                              boolFoundTomorrow = True
                          End If
                      Next
              
                      If boolFoundToday Then
                          hs.writelog("ok", "Found Today")
                      End If
              
                      If boolFoundTomorrow Then
                          hs.writelog("ok", "Found Tomorrow")
                      End If
              Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
              Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




              HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

              Comment


                #8
                OK I thought you had already formatted the string of dates. You can strip off the first part of the string and leave the dates or perhaps it would be better to look at processing the raw json data in a more efficient manner.

                Do you have an example of the raw json data that you're working with?

                Paul..

                Comment


                  #9
                  Wait i send you pm

                  Originally posted by sooty View Post
                  OK I thought you had already formatted the string of dates. You can strip off the first part of the string and leave the dates or perhaps it would be better to look at processing the raw json data in a more efficient manner.

                  Do you have an example of the raw json data that you're working with?

                  Paul..
                  Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                  Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                  HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                  Comment


                    #10
                    Solved Thanks to Sooty!
                    Preferred -> Jon's Plugins, Pushover, Phlocation, Easy-trigger,
                    Rfxcom, Blade Plugins, Pushbullet, homekit, Malosa Scripts




                    HS3Pro 4.1.14.0 on windows 10 enterprise X64 on hp quadcore laptop 8 GB.

                    Comment

                    Working...
                    X