處理JSON格式,我需要從這個數組難的目標C
({
1 = 4;
},
{
8 = 20;
})
其實我需要的輸出像{"custom":{"1":"3","8":"21"}}
轉換JSON字符串,但我得到「{\n \"custom\" : \"[\\n {\\n \\\"1\\\" : \\\"4\\\"\\n },\\n {\\n \\\"8\\\" : \\\"20\\\"\\n }\\n]\"\n}"
這裏是我的代碼
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:mydict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
有什麼辦法可以得到像這樣的輸出:{"custom":{"1":"3","8":"21"}}
謝謝你,我現在得到[{「1」:「4」},{「8」:「20」}]。你可以幫助如何使這個{「7」:「8」,「8」:「5」} – Subramani
@Subramani - 你有一個字典數組,如果你想輸出一個單一的JSON字典產生一個單一的在進行JSON轉換之前從您的數組中提取字典。 – CRD
@CRD yahooooooo我得到了你,非常感謝你 – Subramani