zoukankan      html  css  js  c++  java
  • json字符串转对象

    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);
  • 相关阅读:
    使用JSONPath
    JSON 返回值JSONPath Syntax
    IntelliJ IDEA 打包Maven 构建的 Java 项目
    JMeter(7) 优化判断返回类型和返回值
    Windows copy
    Windows del
    Windows exit
    Windows netsh
    Windows start
    Windows taskkill
  • 原文地址:https://www.cnblogs.com/Ghazi/p/6123668.html
Copyright © 2011-2022 走看看