我有這個URL返回JSON。我寫的JSON的解釋如下:NSDictionary突然變成NSArray
NSData* Data = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error];
NSDictionary *schools = [NSJSONSerialization JSONObjectWithData:Data options:kNilOptions error:nil];
然後,我編寫的字典到一個文件:
NSString *filePath = [documentsDirectory stringByAppendingPathComponent:@"schools.plist"];
[schools writeToFile:filePath atomically:YES];
運行代碼時,我檢查字典,似乎包含有效對象:
然而,當我檢查磁盤上的文件,它看起來像一個數組:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array>
<dict>
<key>Id</key>
<string>ffefe0f7-23bf-471f-8e99-58ada0229921</string>
<key>Name</key>
這是預期的行爲嗎?我的代碼中的其他方法依賴於從該文件中獲取字典。
'的NSLog(@ 「類:%@」,[NSJSONSerialization JSONObjectWithData:數據選項:kNilOptions錯誤:零]類] )'真的返回一個NSDictionary?難道你的JSON實際上返回一個NSArray?另外,請檢查「學校」是否被「覆蓋」(重置)在某處 – Larme
它看起來像'JSONObjectWithData'返回包含'NSDictionary's的'NSArray's。 – keithbhunter
看我添加的插圖。當「學校」啓動時,似乎沒有json數據 – Sjakelien