C # Use the iphone-plist-net library to read and write plist files

Source: Internet
Author: User

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 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.