u010650772 2013-08-27 12:34 采纳率: 100%
浏览 2590
已采纳

在wp7上用JSON.NET反序列化json串时遇到了问题

在手机端获得了这样的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”的值。"
~ ~

求各位大神帮我看看我写的类是不是有问题?谢谢!

  • 写回答

3条回答

  • life_is_a_fool 2013-08-28 06:10
    关注

    在jsp中有个eval的,不知道可以运用不,用了次标签可以还原到开始的json状态,具体的我不知道这个东西怎么用。你看看,或许可以有收获。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题