【发布时间】:2014-02-04 16:26:36
【问题描述】:
基于http://json2csharp.com/,我有以下类:
public class Meta
{
public string reason { get; set; }
public bool success { get; set; }
}
public class Objects
{
public int current_workspace { get; set; }
public string first_name { get; set; }
public bool is_staff { get; set; }
public string key { get; set; }
public string last_login { get; set; }
public string last_name { get; set; }
public string username { get; set; }
}
public class RootObject
{
public Meta meta { get; set; }
public Objects objects { get; set; }
}
如何使用以下方法获取类的各个字段中的数据:
public static void GetLoginDetails(string username, string password)
{
// Customize URL according to geo location parameters
var url = string.Format(loginUrl, username, password);
// Syncronious Consumption
var syncClient = new WebClient();
var content = syncClient.DownloadString(url);
if (!string.IsNullOrEmpty(content))
{
JsonConvert.DeserializeObject(content);
}
}
我尝试了一些示例,但对象类字段为空 注意:通过调试,我可以看到 content 变量中的数据。
【问题讨论】:
标签: c# json web-services json.net