内的数据
基于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);
}
}
我尝试了一些示例,但是对象类字段是空的NB:从调试中,我可以看到 content varible。
更改此
JsonConvert.DeserializeObject(content);
到这个
RootObject myRootObject = JsonConvert.DeserializeObject<RootObject>(content);
然后,如果不是null,即myRootObject.meta.reason
,myRootObject.objects.key
等,您可以访问myRootObject
的任何属性