I posted a simple code for generating a plist file in C # before, but what if I want to read the plist file in turn? Is there a class library that implements such a function? The answer is yes. I found an iphone-plist-net library on the Internet in the afternoon and tried it. It is very convenient to read the code:
[Csharp]
// Write
Var dic = new PListDict ();
Dic ["name"] = new PListString ("WangQiuyun ");
Dic ["age"] = new PListInteger (25 );
Dic ["address"] = new PListString ("yongtaizhuang, Haidian District, Beijing ");
Var arr = new PListArray ();
Arr. Add (new PListInteger (1 ));
Arr. Add (new PListInteger (2 ));
Arr. Add (new PListInteger (3 ));
Arr. Add (new PListInteger (4 ));
Arr. Add (new PListInteger (5 ));
Dic ["array"] = arr;
Var myRoot = new PListRoot ();
MyRoot. Root = dic;
MyRoot. Save ("mytest. plist", PListFormat. Xml );
MyRoot. Save ("mytest. bplist", PListFormat. Binary );
[Csharp]
// Read
PListRoot root = PListRoot. Load (@ "mytest. plist ");
PListDict dic = (PListDict) root. Root;
PListString name = (PListString) dic ["name"];
ListBox1.Items. Add (name. Value + "type:" + name. Tag );
PListInteger age = (PListInteger) dic ["age"];
ListBox1.Items. Add (age. Value + "type:" + age. Tag );
PListString address = (PListString) dic ["address"];
ListBox1.Items. Add (address. Value + "type:" + address. Tag );
PListArray arr = (PListArray) dic ["array"];
ListBox1.Items. Add (PListInteger) arr [0]). Value );
ListBox1.Items. Add (PListInteger) arr [1]). Value );
ListBox1.Items. Add (PListInteger) arr [2]). Value );
ListBox1.Items. Add (PListInteger) arr [3]). Value );
ListBox1.Items. Add (PListInteger) arr [4]). Value );
[Csharp]
// Read/write
PListRoot root = PListRoot. Load ("mytest. plist ");
Using (MemoryStream memStream = new MemoryStream ())
{
Root. Save (memStream, PListFormat. Xml );
TextBox1.Text = Encoding. UTF8.GetString (memStream. ToArray ());
}
Root. Save ("com. apple. springboard. XML. plist", PListFormat. Xml );
Root. Save ("com. apple. springboard. BIN. plist", PListFormat. Binary );