我能够将XML数据读入字典,代码如下。
NSString *testXMLString = @"<items><item id=\"0001\" type=\"donut\"><name>Cake</name><ppu>0.55</ppu><batters><batter id=\"1001\">Regular</batter><batter id=\"1002\">Chocolate</batter><batter id=\"1003\">Blueberry</batter></batters><topping id=\"5001\">None</topping><topping id=\"5002\">Glazed</topping><topping id=\"5005\">Sugar</topping></item></items>";
NSError *parseError = nil;
NSDictionary *xmlDictionary = [XMLReader dictionaryForXMLString:testXMLString error:&parseError];
NSLog(@"%@", xmlDictionary);
在终端输出如下。
items = {
item = {
batters = {
batter = (
{
id = 1001;
text = Regular;
},
{
id = 1002;
text = Chocolate;
},
{
id = 1003;
text = Blueberry;
}
);
};
id = 0001;
name = {
text = Cake;
};
ppu = {
text = "0.55";
};
topping = (
{
id = 5001;
text = None;
},
{
id = 5002;
text = Glazed;
},
{
id = 5005;
text = Sugar;
}
);
type = donut;
};
}; }
如何在plist中保存此词典?
答案 0 :(得分:1)
您可以使用[mydict writeToFile:@"/hello.plist" atomically:YES]
..................................