.net Restful queries

Started by stanl, June 27, 2019, 05:28:09 AM

Previous topic - Next topic

td

Did a quick search on the system for .burgerFlipper examples parsing json and surprisingly found several.  Here is one of them:

Code (winbatch) Select
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

Quote from: td on July 08, 2019, 07:42:06 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

stanl

Quote from: td 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:


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

Quote from: stanl on July 08, 2019, 02:07:02 PM
Quote from: td on July 08, 2019, 07:42:06 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