2011-05-13 54 views
0

我有这个课程。asp.net json .net对象

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 

namespace TestConnect 
{ 
    public class UserInfo 
    { 
     public string id { get; set; } 
     public string name { get; set; } 
     public string picture { get; set; } 
     public string bio { get; set; } 
     public string quotes { get; set; } 
     //public HometownInfo from { get; set; 
     public From hometown { get; set; } 
     public string relationship { get; set; } 
     public string gender { get; set; } 
     public List<Education> data { get; set; } 
    } 

    public class Education 
    { 

     public From school { get; set; } 
     public From year { get; set; } 
     //public From [] concentration { get; set; } 
     public string type { get; set; } 

    } 

} 

public class HometownInfo 
{ 
    public string id { get; set; } 
    public string homename { get; set; } 
} 

现在试图做

url = "https://graph.facebook.com/me?fields=education&access_token=" + oAuth.Token; 
json = oAuth.WebRequest(oAuthFacebook.Method.GET, url, String.Empty); 
Education edu = js.Deserialize<Education>(json); 

foreach(Education_history edu_history in Education.data)给出了一个错误不设置到对象的实例

对象引用。说明:在 当前Web 请求的执行

感谢 用户

回答

0

您是否尝试过在你的代码的各个步骤设置断点,看到它可能会在出现 未处理的异常?

你的代码中的其他地方你必须声明url和json?

是不是js.Deserialize()创建一个新的对象,或者你是否缺少这个 教育edu = new Education();

此外,如果它在网络应用程序中,请确保您的代码被放置在正确的页面事件中,以便它们按正确顺序发生