尝试使用JSON.Net,如果您还没有看到它,它将对您有所帮助。
Json.NET库使在.NET中处理JSON格式的数据变得简单。关键功能包括一个灵活的JSON序列化程序,该序列化程序可用于将.NET类快速转换为JSON并再次转换回;而LINQ为JSON则用于读写JSON。
反序列化在这里讨论。
在JSON文本和.NET对象之间进行转换的最快方法是使用JsonSerializer。JsonSerializer将.NET对象转换为等效的JSON,然后再次返回。
反序列化的基本代码结构如下-
Target仍需要填写以捕获具有适当类型的其余已解析数据项。提到的文件
json.txt包含来自上面URL的数据。
using System;using System.IO;using Newtonsoft.Json;public class NameAndId{ public string name; public int id; }public class Data{ public NameAndId[] data;}public class Target{ public string id; public NameAndId from; public Data likes;}public class Program{ static void Main(string[] args) { string json = File.ReadAllText(@"c:tempjson.txt"); Target newTarget = JsonConvert.DeserializeObject<Target>(json); }}这是JSON流的第一部分供参考:
{ "id": "367501354973", "from": { "name": "Bret Taylor", "id": "220439" }, "message": "Pigs run from our house in fear. Tonight, I am wrapping the pork tenderloin in bacon and putting pancetta in the corn.", "updated_time": "2010-03-06T02:57:48+0000", "likes": { "data": [ { "id": "29906278", "name": "Ross Miller" }, { "id": "732777462", "name": "Surjit Padham" },


