raymond raymond - 6 months ago 18
Swift Question

how can i pass a javascript object from javascript to iOS swift?

i am wondering how can i pass object from javascript to swift.
I don't know which type should i declare the variable in order to receive the javascript object.

the following is my javascript code to create an object

var labs = ["dead","sfdsf","DH-dsfdsfds","DH-sdfdsf"]
var labgrp = {labGrp:"R", labGrpDesc:"fdgfdg",labs:labs}
var labGroups = []
labGroups[0] = labgrp
var labGroup = {labGroups}


how can i pass labGroup to swift? By using JSON??
Please comment it. thank you.

N J N J
Answer

how can i pass labGroup to swift? By using JSON??

YES

Best option to you is JSON .

Pass JSON from Javascript and catch it in Swift


EDIT

see this for converting Javascript object to JSON

var j={"name":"binchen"};
JSON.stringify(j);

Note: download js for above code to work path