Announcement

Collapse
No announcement yet.

Parsing JSON response using Newtonsoft

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

  • Parsing JSON response using Newtonsoft

    I've been search and searching online for an example but the solutions appear to be overly complicated in my opinion.

    I've been able to deserialize a JSON response when it's just a single line but I've having trouble when their's more than one record. For example, here are two records where I just want to get the "watts" from the two records:

    Code:
    {"1":{"pump":1,"name":"Pump 1","type":"VS","time":"2:10 PM","run":10,"mode":0,"drivestate":0,"watts":1656,"rpm":2850,"gpm":0,"ppc":0,"err":0,"timer":1,"duration":"durationnotset","currentrunning":{"mode":"off","value":0,"remainingduration":-1},"externalProgram":{"1":-1,"2":-1,"3":-1,"4":-1},"remotecontrol":1,"power":1,"friendlyName":"Pump 1"},"2":{"pump":2,"name":"Pump 2","type":"None","time":"timenotset","run":"runnotset","mode":"modenotset","drivestate":"drivestatenotset","watts":"wattsnotset","rpm":"rpmnotset","gpm":"gpmnotset","ppc":"ppcnotset","err":"errnotset","timer":"timernotset","duration":"durationnotset","currentrunning":{"mode":"off","value":0,"remainingduration":-1},"externalProgram":{"1":-1,"2":-1,"3":-1,"4":-1},"remotecontrol":"remotecontrolnotset","power":"powernotset","friendlyName":"Pump 2"}}
    Does anyone have an example of doing this? I can be in vb.net or c#. Either way...

    Thanks. Chris

  • #2
    Hello

    This site give me a json file with two section
    https://particulier.edf.fr/bin/edf_r...peAlerte=TEMPO

    My program to put the value in two devices

    Jean-Francois
    Last edited by jfla; May 30th, 2018, 04:34 AM.

    Comment


    • #3
      Merci beaucoup! Your solution worked.

      I also found a slightly different way as follows:

      IMPORTS Newtonsoft.Json
      IMPORTS Newtonsoft.Json.Linq
      Sub Main(parm as object)

      Dim strReturn As String = hs.GetURL(“192.168.1.50”,”/pump/”, FALSE, 3000)
      Dim obj as New JObject

      obj = JsonConvert.DeserializeObject(strReturn)
      Dim rpm1 As String = obj.Value(Of JObject)("1").Value(Of String)("rpm")
      Dim rpm2 As String = obj.Value(Of JObject)("2").Value(Of String)("rpm")

      hs.WriteLog("rpm1", rpm1)
      hs.WriteLog("rpm2", rpm2)

      End Sub
      Last edited by yyz; May 30th, 2018, 07:02 PM.

      Comment

      Working...
      X