作者uranusjr (←这人是超级笨蛋)
看板MacDev
标题Re: [问题] 关於组合JSON字串
时间Tue Apr 23 13:34:45 2013
※ 引述《johnlinvc (阿翔)》之铭言:
: ※ 引述《steny138 (阿辰)》之铭言:
: : 小弟最近开始尝试JSON的格式
: : 因为在组合字串的时候 一直要 EX: \"name\":\"peter\",....
: : 类似以上的方式实在是有点难以阅读
: : 请问有什麽比较好用的方法比较实用
: : 或是可以比较整齐的吗
: : 请大家指点迷津 谢谢~~
: 用JSONKit https://github.com/johnezang/JSONKit
: 用JSONKit 搭配literal NSDictionary可以组出最好阅读的JSON String
: IE:
: NSDictionary * jsonDic = @{@"name" : @"perter", @"age" : @(18)}
: NSString * jsonString = [jsonDic JSONString]
从 iOS 5.0 和 OS X 10.7 开始就有内建 JSON serializer 了
除非你真的很需要 performance 或者需要支援古早的系统
否则直接用就好
NSJSONSerialization Class Reference
http://goo.gl/oKe1S
注意它是吃 NSData, 所以请搭配以下 references 服用
http://goo.gl/hGu90 NSString 的 -initWithData:encoding:
http://goo.gl/hGu90 NSString 的 -dataUsingEncoding:
-dataUsingEncoding:allowLossyConversion:
http://goo.gl/hGu90 NSStringEncoding enum
--
Les grandes et les meilleurs
tone from "Zadok the Priest"
Eine grosse stattliche Veranstaltung
by F. Handel
THE MAIN EVENT! These are the men
Sie sind die Besten
"Champions League" by Tony Britten THESE ARE THE CHAMPIONS!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 220.133.47.18
※ 编辑: uranusjr 来自: 220.133.47.18 (04/23 13:35)