第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

從IOS中的NSDicary生成JSON字符串

從IOS中的NSDicary生成JSON字符串

寶慕林4294392 2019-07-22 16:21:50
從IOS中的NSDicary生成JSON字符串我有一個(gè)dictionary我需要生成一個(gè)JSON string用dictionary..可以轉(zhuǎn)換嗎?你們能幫忙嗎?
查看完整描述

3 回答

?
慕碼人2483693

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊

下面是NSArray和NSDicary的分類,以使這一過程變得非常簡(jiǎn)單。我添加了一個(gè)漂亮打印選項(xiàng)(換行符和制表符,以便于閱讀)。

@interface NSDictionary (BVJSONString)-(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint;@end
@implementation NSDictionary (BVJSONString)

  -(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint {
     NSError *error;
     NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
                                                   options:(NSJSONWritingOptions)    (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
                                                     error:&error];

     if (! jsonData) {
        NSLog(@"%s: error: %@", __func__, error.localizedDescription);
        return @"{}";
     } else {
        return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
     } 
 }@end
@interface NSArray (BVJSONString)- (NSString *)bv_jsonStringWithPrettyPrint:(BOOL)prettyPrint;@end
@implementation NSArray (BVJSONString)-(NSString*) bv_jsonStringWithPrettyPrint:(BOOL) prettyPrint {
    NSError *error;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self
                                                       options:(NSJSONWritingOptions) (prettyPrint ? NSJSONWritingPrettyPrinted : 0)
                                                         error:&error];

    if (! jsonData) {
        NSLog(@"%s: error: %@", __func__, error.localizedDescription);
        return @"[]";
    } else {
        return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    }}@end


查看完整回答
反對(duì) 回復(fù) 2019-07-22
  • 3 回答
  • 0 關(guān)注
  • 823 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)