Can and how do you get remote data (e.g. JSON) into AppleScript?

前端 未结 4 1174
猫巷女王i
猫巷女王i 2021-02-04 19:44

I\'ve got a Web-based API to which I would like to send POST/GET requests via AppleScript. I\'d like to retrieve and parse the response such that I can feed it into another app.

4条回答
  •  醉话见心
    2021-02-04 20:06

    I needed to parse JSON in AppleScript, and made a very simple scriptable background app to do this. It really just ties two frameworks (JSON, Appscript) together.

    It's now available free on the Mac AppStore. You can check out more examples on our website.

    Usage is very simple:

    tell application "JSONHelper"
    
        -- return JSON from an AppleScript list
    
        set jsonString to make JSON from {"A", "B", "C"}
        log jsonString
    
        set asList to read JSON from jsonString
    
        -- return JSON from an AppleScript record
    
        set jsonString to make JSON from {a_string:"string", a_list:{"abc", 123, false, true}}
        log jsonString
    
        -- return an AppleScript record from JSON
    
        set asRecord to read JSON from jsonString
        log asRecord
    
    end tell
    

提交回复
热议问题