| 
 | 
 
刚刚由于需要,要解析json,于是我就各种查资料,然后淫用了第三方Newtonsoft.Json,写完后一堆的报错。原因是我用的 Newtonsoft.Json跟我的Framework.net的版本不一致,搞的我半天找不到问题所在。所以呢我觉得还是有必要说一下。大婶勿喷,偶是新人。 
 
 
首先引用Newtonsoft.Json的时候可以在C:\Windows\Microsoft.NET\Framework看下自己已经安装的有哪些版本,如果是安装了4.0 就引用Net40这个文件夹下的Newtonsoft.Json就可以。下面是个简单的解析过程; 
 
josn的内容为外部加载一个txt文件,放在debug的目录下,内容为{"h":"Hello world!!!"} 
using Newtonsoft.Json.Linq; 
using System.IO; 
 
namespace ConsoleApplication4 
{ 
    class Program 
    { 
        static void Main(string[] args) 
        { 
            string json = File.ReadAllText("data.txt"); 
            JObject obj = JObject.Parse(json); 
            Console.WriteLine((string)obj["h"]); 
            Console.ReadKey(); 
        } 
    } 
} 
 |   
 
 
 
 |