我正在使用以下代码
string strFetchResData = string.Empty;
XmlDocument xmlDoc = new XmlDocument();
double RateId = 299;
bool UseNetMetering = true;
string StartTime = "2/26/2008%2011:00:00%20AM";
string EndTime = "2/26/2009%2010:00:00%20AM";
using (var client = new CookieAwareWebClient())
{
Uri uri = new Uri("https://www.myServiceUrl.com/Services.svc/SynthesizedBill?RateId=" + RateId + "&UseNetMetering=" + UseNetMetering + "&StartTime=" + StartTime + "&EndTime=" + EndTime + "");
client.Credentials = new NetworkCredential(ConfigurationManager.AppSettings["CPRUserName"], ConfigurationManager.AppSettings["CPRPassword"]);
strFetchResData = client.DownloadString(uri);
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(strFetchResData);
objSynthesizedData.PowerBill = JsonConvert.SerializeXmlNode(doc).Replace(@"@", @"").Remove(1, 44);
am使用数据成员
[DataContract]
public class SynthesizedPowerBill
{
[DataMember]
public string PowerBill { get; set; }
}
但是我没有得到json格式的输出,
为什么格式不是以JSON格式出现的?它像一个普通的字符串,我想要json格式。 请帮帮我..
答案 0 :(得分:1)
改为使用DataContractJsonSerializer?
http://msdn.microsoft.com/en-us/library/bb410770(v=vs.110).aspx