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 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题