4
目前爲了使用這個函數,我將我的對象「轉換」爲一個字典。即屬性名稱成爲鍵,屬性值成爲值。創建一個與NSJSONSerialization的dataWithJSONObject一起使用的對象:options:error:
有沒有辦法正確做到這一點,使一個對象將與此功能?
即與用於NSUserDefaults
的encodeWithCoder
和initWithCoder
類似。
我想做...
NSData *data = [NSJSONSerialization dataWithJSONObject:myObject options:0 error:nil];
在現階段,我這樣做...
NSData *data = [NSJSONSerialization dataWithJSONObject:[myObject dictionaryRepresentation] options:0 error:nil];
不,因爲'NSJSONSerialization'沒有關於外部類的線索。爲什麼現在的方法不好?它看起來相當好/簡單/優雅。 – 2013-02-11 17:55:48
它的作品我只是想知道如果有另一種方式。看起來有點像矯枉過正,可以轉換成字典,然後轉換成數據,想知道是否可以削減中間步驟。 – Fogmeister 2013-02-11 17:56:23
不幸的是我不能突然想到一個。 – 2013-02-11 17:56:51