在手机端获得了这样的json串:
[
{"class":"Board","id":1,"articles": [{"class":"Article","id":1}],
"boardName":"122222","boarder": {"class":"User","id":1},
"description":"22222","postCount":0},
{"class":"Board","id":2,"articles":[],"boardName":"555555","boarder":{"class":"User","id":2},"description":"555555","postCount":0}]
我打算用json.NET来解析它。已经把Newtonsoft.Json.dll添加进来。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
然后我写了一系列的类(这里我想用Board这个类来接收json串):
//为接收 Board json 串写的两个类
public class Boarder
{
public string @class { get; set; }
public int id { get; set; }
}
public class Board
{
public string @class { get; set; }
public int id { get; set; }
public List articles { get; set; }
public string boardName { get; set; }
// public Boarder boarder { get; set; }
public User boarder { get; set; }
public string description { get; set; }
public int postCount { get; set; }
}
//为接收 Article json 串写的三个类
/*public class Board
{
public string @class { get; set; }
public int id { get; set; }
}*/
/*public class Owner
{
public string @class { get; set; }
public int id { get; set; }
}*/
public class Article
{
public string @class { get; set; }
public int id { get; set; }
public Board board { get; set; }
public List comments { get; set; }
public string detail { get; set; }
public string lastReplyTime { get; set; }
//public Owner owner { get; set; }
public User owner { get; set; }
public string postTime { get; set; }
public int replyCount { get; set; }
public string title { get; set; }
}
//为接收 User json 串写的三个类
/*public class Article
{
public string @class { get; set; }
public int id { get; set; }
}*/
/*public class Comment
{
public string @class { get; set; }
public int id { get; set; }
}*/
public class User
{
public string @class { get; set; }
public int id { get; set; }
public string address { get; set; }
public List articles { get; set; }
public object birthday { get; set; }
public List comments { get; set; }
public string email { get; set; }
public string lastLoginTime { get; set; }
public string nickName { get; set; }
public string password { get; set; }
public string picture { get; set; }
public string qq { get; set; }
public string registerTime { get; set; }
public string sex { get; set; }
public string signDetail { get; set; }
}
//为接收 Comment json 串写的三个类
/*public class Article
{
public string @class { get; set; }
public int id { get; set; }
}*/
/*public class Owner
{
public string @class { get; set; }
public int id { get; set; }
}*/
public class Comment
{
public string @class { get; set; }
public int id { get; set; }
public Article article { get; set; }
public string detail { get; set; }
//public Owner owner { get; set; }
public User owner { get; set; }
public string postTime { get; set; }
}
接收类写完后,我用Board类来接收json串:
List p1 = JsonConvert.DeserializeObject>(e.Result.ToString()); //获取到的json数据反序列化
结果程序报错,错误信息为:
“Newtonsoft.Json.JsonConvert.DefaultSettings 未能计算表达式的值 System.Func"
"emptyArray = 有关包含类的信息不可用,因此无法获取字段“_emptyArray”的值。"
~ ~
求各位大神帮我看看我写的类是不是有问题?谢谢!