程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> deserialize-在wp7上用JSON.NET反序列化json串時遇到了問題

deserialize-在wp7上用JSON.NET反序列化json串時遇到了問題

編輯:編程綜合問答
在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”的值。"
~ ~

求各位大神幫我看看我寫的類是不是有問題?謝謝!

最佳回答:


在jsp中有個eval的,不知道可以運用不,用了次標簽可以還原到開始的json狀態,具體的我不知道這個東西怎麼用。你看看,或許可以有收獲。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved