ruby - using NSJSONSerialization in RubyMotion -
ruby - using NSJSONSerialization in RubyMotion -
i'm using rubymotion , trying serialize object json. i'm not getting error message causes app crash.
class foo attr_accessor :name end e = pointer.new(:object) testitem = foo.new testitem.name = "test" testjson = nsjsonserialization.datawithjsonobject(testitem, options:0, error: e)
can see if im using class correctly? (or know alternative)
there nil wrong call. problem data. top level object in testitem
must nsarray
or nsdictionary
.
you can utilize rubymotion arrays , hashes since array < nsmutablearray < nsarray
, hash < nsmutabledictionary < nsdictionary
.
try these sample testitems call:
testitem = ["test"] testitem = {"names" => ["fred", "joe", "mike"], "ages" => [17, 63, 28]}
from nsjsonserialization.h:
/* class converting json foundation objects , converting foundation objects json. object may converted json must have next properties: - top level object nsarray or nsdictionary - objects nsstring, nsnumber, nsarray, nsdictionary, or nsnull - dictionary keys nsstrings - nsnumbers not nan or infinity */
ruby rubymotion
Comments
Post a Comment