将WEBCLIENT上包装的XML转换为JSON

时间:2019-07-16 11:31:44

标签: c# json xml-parsing json.net jsonparser

请协助将以下内容转换为JSON

using (WebClient wc = new WebClient())
{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";string HtmlResult = wc.UploadString(URI, Parameters);
string result = "<?xml version=\"1.0\" encoding=\"uft - 8\"?><SendingSMSResult xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"xmlns=\"https://xxxxxxx/sendsms\">\n<Message> OK</Message >\n < Result > true </ Result >\n < messageId > 1235 </ messageId>< RejectedNumbers /></ SendingSMSResult >";var xml = XDocument.Parse(result);
 var SMSResult = xml.Element("{https://xxxxx/sms}SendingSMSResult");var elements = SMSResult.Elements();Result.Set(executionContext, elements.Single(x => x.Name.LocalName == "Message").Value);MessageResultId.Set(executionContext, elements.Single(x => x.Name.LocalName == "messageId").Value);
}


{
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";string HtmlResult = wc.UploadString(URI, Parameters);
string result = "<?xml version=\"1.0\" encoding=\"uft - 8\"?><SendingSMSResult xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"xmlns=\"https://xxxxxxx/sendsms\">\n<Message> OK</Message >\n < Result > true </ Result >\n < messageId > 1235 </ messageId>< RejectedNumbers /></ SendingSMSResult >";var xml = XDocument.Parse(result);
 var SMSResult = xml.Element("{https://xxxxx/sms}SendingSMSResult");var elements = SMSResult.Elements();Result.Set(executionContext, elements.Single(x => x.Name.LocalName == "Message").Value);MessageResultId.Set(executionContext, elements.Single(x => x.Name.LocalName == "messageId").Value);
}

0 个答案:

没有答案