RestSharp和WP7没有返回正确的数据
本文关键字:数据 返回 WP7 RestSharp | 更新日期: 2023-09-27 18:16:40
请原谅我糟糕的代码和无知,这只是一个深夜的hack来测试一些东西。
无论如何,我试图在WP7中使用RESTSharp,但我遇到了一个障碍,我无法弄清楚。
谁能看一下吗?
代码:namespace McMyAdmin.Data
{
[DataContract]
public class Status
{
private bool isRunning;
private bool isReady;
private int ram;
private int maxRam;
private int users;
private int maxusers;
private DateTime startDateTime;
private int cpuUsage;
[DataMember(Name = "running")]
public bool IsRunning { get { return isRunning; } set { isRunning = value; } }
[DataMember(Name = "ready")]
public bool IsReady { get { return isReady; } set { isReady = value; } }
[DataMember(Name = "ram")]
public int Ram { get { return ram; } set { ram = value; } }
[DataMember(Name = "maxram")]
public int MaxRam { get { return maxRam; } set { maxRam = value; } }
[DataMember(Name = "users")]
public int Users { get { return users; } set { users = value; } }
[DataMember(Name = "maxusers")]
public int MaxUsers { get { return maxusers; } set { maxusers = value; } }
[DataMember(Name = "starttime")]
public DateTime StartDateTime { get { return startDateTime; } set { startDateTime = value; } }
[DataMember(Name = "cpuusage")]
public int CPUUsage { get { return cpuUsage; } set { cpuUsage = value; } }
public Status GetStatus()
{
var webclient = new RestClient
{
BaseUrl = "http://localhost:8080",
Authenticator = new HttpBasicAuthenticator("admin","xxxxxxxx")
};
var request = new RestRequest("data.json", Method.GET);
request.AddParameter("req", "status");
Status test = new Status();
var sd = webclient.ExecuteAsync<Status>(request, (response) =>
{
test.isRunning = response.Data.isRunning;
test.isReady = response.Data.isReady;
test.Ram = response.Data.Ram;
test.MaxRam = response.Data.MaxRam;
test.Users = response.Data.Users;
test.MaxUsers = response.Data.MaxUsers;
test.StartDateTime = response.Data.StartDateTime;
test.CPUUsage = response.Data.CPUUsage;
});
return test;
}
}
}
这不会产生任何错误,而是产生以下的垃圾数据
CPUUsage 0 int
IsReady false bool
IsRunning false bool
MaxRam 0 int
MaxUsers 0 int
Ram 0 int
startDateTime {1/1/0001 12:00:00 AM} System.DateTime
Users 0 int
与Json相比这是完全错误的
{"status":200,"running":true,"ready":true,"stopping":false,"failed":false,"failmsg":"","maxram":1024,"users":0,"maxusers":8,"userinfo":{},"time":"2011-12-03 23:46:54","ram":"241","starttime":"12/03/2011 17:32:04","cpuusage":0}
Thanks in advance
忽略
DataMember
属性。查看反序列化文档,或者试试Hammock。