2016-10-19 14 views
-1

是否有任何工具,包括在線服務和macOs應用程序來美化嵌套的NSDictionary結果是這樣的?任何工具來美化嵌套的NSDictionary結果

{ 
     id = 1; 
     testName = my name; 
     createDate = 20021023; 
     likeNumber = 0; 
     statusList = ({ 
       appleId = 1; 
       orangeName = 81; 
       itsStatus = YES; 
     }); 
     text = test; 
     type = Text; 
    }, 

我的意思是摺疊(關閉並打開)樹節點很容易。

目前,在JSONjsonformatter上有很多用於此目的的在線工具。

+0

是你的字典JSONafiable?因爲你可以只打印它作爲JSON然後使用其他工具之一..? – Fonix

+0

打印意味着什麼?或通過代碼縮進? – Larme

+0

@Larme他們都不是,見https://jsonformatter.curiousconcept.com/ –

回答

0

如的Fonix提到的,NSDictionary轉換爲JSON然後用JSON工具用於這一目的的最佳途徑:

+(NSString *)dictionaryToJson:(NSDictionary *)dictionary { 
    NSError *error; 
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary 
                 options:NSJSONWritingPrettyPrinted // Pass 0 if you don't care about the readability of the generated string 
                 error:&error]; 

    NSString *jsonString; 
    if (! jsonData) { 
     NSLog(@"Got an error: %@", error); 
     jsonString = [error localizedDescription]; 
    } else { 
     jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 
    } 
    return jsonString; 
}