简体   繁体   English

如何调用以json字符串形式传递的函数

[英]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}} . 我正在从后端读取一个JSON文件,该文件的参数包含一个带有参数的函数{ "function": {"arg1": 45, "arg2": 73}} I would like to execute the function using the arguments specified in the JSON string. 我想使用JSON字符串中指定的参数执行函数。 How would I implement this in Swift 3? 我将如何在Swift 3中实现呢?

You can execute javascript in an instance of WKWebView and get the result back with WKWebView.evaluateJavaScript(_:completionHandler:) . 您可以在WKWebView的实例中执行javascript,并通过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. 您可以使用JSONSerialization ,SwiftJSON,ObjectMapper或任何其他许多JSON库从JSON抓取参数的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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