C#使用iphone-plist-net库读写plist文件

之前我贴过一段很简单的C#生成plist文件的代码,但是反过来如果要读取plist文件呢?有没有实现这样功能的类库呢?答案是肯定的,下午在网上找了一个iphone-plist-net库试用了一下感觉很是方便,看代码:

            //写入
            var dic = new PListDict();
            dic["name"] = new PListString("WangQiuyun");
            dic["age"] = new PListInteger(25);
            dic["address"] = new PListString("北京海淀区永泰庄");
            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); 

            //读取  
            PListRoot root = PListRoot.Load(@"mytest.plist");
            PListDict dic = (PListDict)root.Root;

            PListString name = (PListString)dic["name"];
            listBox1.Items.Add(name.Value+" 类型:"+name.Tag);

            PListInteger age = (PListInteger)dic["age"];
            listBox1.Items.Add(age.Value + " 类型:" + age.Tag);

            PListString address = (PListString)dic["address"];
            listBox1.Items.Add(address.Value + " 类型:" + 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);

            //读写
            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);

iphone-plist-net库及示例程序都在我的资源:http://download.csdn.net/detail/wangqiuyun/4541196

  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值