1、添加引用
2、添加命名空间
using System.Web; using System.Web.Script.Serialization;
3、
OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Multiselect = true; fileDialog.Title = "请选择文件"; fileDialog.Filter = "(*.txt)|*.txt"; if (fileDialog.ShowDialog() == DialogResult.OK) { string file = fileDialog.FileName; string text = System.IO.File.ReadAllText(file, Encoding.Default); JavaScriptSerializer js = new JavaScriptSerializer(); Dictionary<object, object> dic = js.Deserialize<Dictionary<object, object>>(text); foreach (object key in dic.Keys) { int x = Convert.ToInt16(key); int y = Convert.ToInt16(dic[key]); point pt = new point(x, y); pl.Add(pt); } Point_databind(pl); }
使用JObject
1、添加命名空间
using Newtonsoft.Json.Linq;
2、
var obj = JObject.Parse(text);
时间: 2024-10-12 15:50:24