Announcement

Collapse
No announcement yet.

Save JSON file to HTML folder

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

  • Save JSON file to HTML folder

    I want to save JSON data from a web API into a file and place said file in the html folder.

    Can someone share a simple script to do this? I'm guessing I'm probably missing an import. I have the following so far:

    Code:
    Imports System.Web.Script.Serialization
    
    Sub Main(ByVal Parms As Object)
      Try
        Dim getData As String = hs.GetURL("https://tools.learningcontainer.com/sample-json.json", "/", False, 80)
        File.WriteAllText(@"C:\Program Files (x86)\HomeSeer HS3\html\sample.json",JsonConvert.SerializeObject(getData, Newtonsoft.Json.Formatting.Indented))
        'For later deserialization of the JSON data
        'Dim jsonData As Object = New JavaScriptSerializer().Deserialize(Of Object)(getData)
      Catch ex As Exception
        hs.WriteLogEx("JSON", "ERROR: Exception in script: " & ex.Message, "#FF0000")
      End Try
    End Sub

  • #2
    You can go single line if you wished...

    Code:
    Sub Main(ByVal Parm As Object)
    My.Computer.FileSystem.WriteAllText(hs.getapppath & "\html\stuff.json",hs.GetURL("https://tools.learningcontainer.com", "/sample-json.json", False, 80), False)
    End Sub
    My Plugins:

    Pushover 3P | DoorBird 3P | Current Cost 3P | Velleman K8055 3P | LAMetric 3P | Garadget 3P | Hive 3P |
    Yeelight 3P | Nanoleaf 3P

    Comment


    • #3
      Thank you. Worked like a charm <3

      Comment

      Working...
      X