Re: [問題] 關於組合JSON字串

看板MacDev作者 (←這人是超級笨蛋)時間12年前 (2013/04/23 13:34), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串3/3 (看更多)
※ 引述《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)
文章代碼(AID): #1HTXrtrc (MacDev)
討論串 (同標題文章)
文章代碼(AID): #1HTXrtrc (MacDev)