如何调用在json字符串中作为字符串传递的函数

时间:2017-05-10 23:29:11

标签: json swift closures

我正在从后端读取一个JSON文件,其参数包含带参数def fibonacci_sequence(n): x = [1, 1, 1] [x.append(x[-1] + x[-2] + x[-3]) for i in range(n - len(x))] return x import time n = int(raw_input("Enter the size of Fibonacci-3 sequence: ")) start_time = time.time() print fibonacci_sequence(n) print "The time to compute the Fibonacci-3 sequence is: %s" % (time.time() - start_time) 的函数。我想使用JSON字符串中指定的参数执行该函数。我如何在Swift 3中实现它?

1 个答案:

答案 0 :(得分:0)

您可以在WKWebView的实例中执行javascript,并使用WKWebView.evaluateJavaScript(_:completionHandler:)返回结果。你需要函数的实际代码,我在你的样本中没有看到。您可以使用JSONSerialization,SwiftJSON,ObjectMapper或任何其他许多JSON库从JSON中获取参数的值。