有人可以請與下面的地方幫助(其中我很努力形成查詢)的LINQ to XML轉換器
XML
<?xml version="1.0" encoding="UTF-8"?>
<response id="1545346343">
<date>2013-10-01 12:01:55.532999</date>
<status>
<current>open</current>
<change_at>16:00:00</change_at>
</status>
<message>Market is open</message>
</response>
類
public class MarketClockResponse
{
public Response response { get; set; }
}
public class Response
{
public string Id { get; set; }
public string date { get; set; }
public Status status { get; set; }
public string message { get; set; }
}
public class Status
{
public string current { get; set; }
public string change_at { get; set; }
}
我的解決辦法:
public void example3()
{
var xElem = XElement.Load("test.xml");
var myobject = xElem.Descendants("response").Select(
x => new MarketClockResponse
{
//Struggling to proceed from here
});
}
XML是否始終只包含一個'response'元素? – MarcinJuraszek
什麼查詢?問題是什麼。 – Liam
他不知道如何從xelement構建對象 – Jonesopolis