Author Topic: .net Restful queries  (Read 743 times)

td

  • Tech Support
  • *****
  • Posts: 3054
    • WinBatch
Re: .net Restful queries
« Reply #35 on: July 08, 2019, 09:26:11 am »
Did a quick search on the system for .burgerFlipper examples parsing json and surprisingly found several.  Here is one of them:

Code: Winbatch
jsonText=$"{"menu":: {
    "header":: "SVG Viewer",
    "items":: [
        {"id"::  "Open"},
        {"id"::  "OpenNew", "label":: "Open New"},
        null,
        {"id"::  "ZoomIn", "label":: "Zoom In"},
        {"id"::  "ZoomOut", "label":: "Zoom Out"},
        {"id"::  "OriginalView", "label":: "Original View"},
        null,
        {"id":: "Quality"},
        {"id":: "Pause"},
        {"id":: "Mute"},
        null,
        {"id":: "Find", "label":: "Find..."},
        {"id":: "FindAgain", "label":: "Find Again"},
        {"id":: "Copy"},
        {"id":: "CopyAgain", "label":: "Copy Again"},
        {"id":: "CopySVG", "label":: "Copy SVG"},
        {"id":: "ViewSVG", "label":: "View SVG"},
        {"id":: "ViewSource", "label":: "View Source"},
        {"id":: "SaveAs", "label":: "Save As"},
        null,
        {"id":: "Help"},
        {"id":: "About", "label":: "About Adobe CVG Viewer..."}
    ]
}}$"



; Assemblies used.
ObjectClrOption("useany", 'System.Xml.Linq')
ObjectClrOption("useany", 'System.Runtime.Serialization')

; Load the json text into a byte array.
Encoding = ObjectClrNew('System.Text.Encoding')
ByteArrayJson = Encoding.UTF8.GetBytes(jsonText)

;Creates An XmlDictionaryReader that can process JavaScript Object Notation (JSON) data.
objJsonRWFactory = ObjectClrNew('System.Runtime.Serialization.Json.JsonReaderWriterFactory')
XmlDictionaryReaderQuotas = ObjectClrNew('System.Xml.XmlDictionaryReaderQuotas')
objReader = objJsonRWFactory.CreateJsonReader( ByteArrayJson, XmlDictionaryReaderQuotas.Max)

objXElement = objectClrNew("System.Xml.Linq.XElement")
objRoot     = objXElement.Load(objReader)

;; Create a few XName objects for later use.
objXName     = objectClrNew("System.Xml.Linq.XName")
objNameItems = objXName.Get("items")
objNameItem  = objXName.Get("item")
objNameId    = objXName.Get("id")

; Get the Id values.
objColMenus = objRoot.Elements(objXName.Get("menu"))
foreach objMenus in objColMenus
   objColItems = objMenus.Elements(objNameItems)
   foreach objItems in objColItems
      objColItem = objItems.Elements(objNameItem)
      foreach objItem in objColItem
         objColId = objItem.Elements(objNameId)
         foreach objId in objColid
            Pause("objId.Value", objId.Value)
         next
      next
   next
next
 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

stanl

  • Pundit
  • *****
  • Posts: 946
Re: .net Restful queries
« Reply #36 on: July 08, 2019, 02:07:02 pm »
Not sure what you attempting to do with the "encoded:fmt" parameter but "encoded" certainly isn't a valid variant type. 


Basically these were variables created earlier in the script, so the line would be interpreted as:


response oClient.PostAsync('https://geocode.xyz/','Baum Halls - 8388 Wilshire Blvd., Ste. 444 - Beverly Hills, CA 90211?json=1'.Result


and one of the classes of PostAsync was uri,string

stanl

  • Pundit
  • *****
  • Posts: 946
Re: .net Restful queries
« Reply #37 on: July 08, 2019, 02:29:39 pm »
Did a quick search on the system for .burgerFlipper examples parsing json and surprisingly found several.  Here is one of them:


Yeah, in a earlier post I mentioned about trying serialization. Probably would have generated a whole new thread walking through re-fitting C# examples into WB - but you have significantly added to the topic.

td

  • Tech Support
  • *****
  • Posts: 3054
    • WinBatch
Re: .net Restful queries
« Reply #38 on: July 09, 2019, 07:57:19 am »
Not sure what you attempting to do with the "encoded:fmt" parameter but "encoded" certainly isn't a valid variant type. 


Basically these were variables created earlier in the script, so the line would be interpreted as:


response oClient.PostAsync('https://geocode.xyz/','Baum Halls - 8388 Wilshire Blvd., Ste. 444 - Beverly Hills, CA 90211?json=1'.Result


and one of the classes of PostAsync was uri,string

The PostAsync method has 4 overloads.  Two of them take two parameters.  In both cases, the second parameter is a reference to a HttpContent class object.  The HttpContent object contains the data enclosed in the body of the HTTP POST request message that is sent to the server. 
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade