微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

对json文件进行筛选并导出到新的json文件

using Newtonsoft.Json;using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;namespace Screen{    public partial class Form1 : Form    {        public Form1()        {            InitializeComponent();        }        private void button1_Click(object sender,EventArgs e)        {            string jsonfile = @"C:\Users\Administrator\Desktop\支行信息.json";            string jsonfileOutput = @"C:\Users\Administrator\Desktop\支行信息_filter.json";            //读取            string txt =  System.IO.File.ReadAllText(jsonfile);                                    var bankList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<BankInfo>>(txt);            //筛选            bankList = bankList.Where(p => new List<string>() { "中国工商银行","中国农业银行","中国建设银行","交通银行","中国银行","邮政储蓄银行" }.Contains(p.bank_name)).ToList();            //写入            var resTxt = Newtonsoft.Json.JsonConvert.SerializeObject(bankList);            System.IO.File.WriteallText(jsonfileOutput,resTxt,Encoding.UTF8);              }    }}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐