简体   繁体   中英

How to call a function passed as a string in a json string

I am reading from a backend, a JSON file with parameters which include a function with arguments { "function": {"arg1": 45, "arg2": 73}} . I would like to execute the function using the arguments specified in the JSON string. How would I implement this in Swift 3?

You can execute javascript in an instance of WKWebView and get the result back with WKWebView.evaluateJavaScript(_:completionHandler:) . You need the actual code for the function though, which I don't see in your sample. You can grab the values of the arguments from the JSON with JSONSerialization , SwiftJSON, ObjectMapper or any of the other many JSON libraries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM