解析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; using Newtonsoft.Json; using System.IO; using Newtonsoft.Json.Linq; namespace test解析json { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { Album_List a = new Album_List(); string s2 = "[{'album_scope':1,'picture_num':'1982','album_sign':'1190af2198dfd63dacc4f14f4d08016a103f0383','album_name':'\u538b\u529b\u6d4b\u8bd5\u76f8\u518c2','is_secret':0},{'album_scope':0,'picture_num':'1982','album_sign':'4b44e2e6547497365a062dad521739bebcfd4754','album_name':'\u538b\u529b\u6d4b\u8bd5\u76f8\u518c','is_secret':0},{'album_scope':0,'picture_num':'3','album_sign':'1190af2198dfd63dad88f24f4d08016a103f0377','album_name':'2014-03-05','is_secret':0},{'album_scope':1,'picture_num':'6','album_sign':'7d6ec7be7f93282e00239d5e3ba9d7f301860869','album_name':'test\u76f8\u518c04','is_secret':0},{'album_scope':1,'picture_num':'6','album_sign':'a7027a36a2d6c3d0998f3e18edff7f93292e1369','album_name':'test\u76f8\u518c03','is_secret':0},{'album_scope':1,'picture_num':'100','album_sign':'dad60f8a6edd8f3d741bee2d8068e8d928abf06a','album_name':'test\u76f8\u518c02','is_secret':0},{'album_scope':1,'picture_num':'50','album_sign':'392b1a684a86c51227e42e047ff9ba6351771c72','album_name':'test\u76f8\u518c01','is_secret':0}]";
List<Album_List> _list = JsonConvert.DeserializeObject<List<Album_List>>(s2); foreach (Album_List aa in _list) { foreach (System.Reflection.PropertyInfo Pppp in aa.GetType().GetProperties()) { this.textBox1.Text += Pppp.Name; this.textBox1.Text += ":"; this.textBox1.Text += aa.GetType().GetProperty(Pppp.Name).GetValue(aa, null); this.textBox1.Text += "\r\n"; } } ; } } public class Album_List { public string album_scope { get; set; } public string picture_num { get; set; } public string album_sign { get; set; } public string album_name { get; set; } public string is_secret { get; set; } } }