如何解析这个 XML。在这里,我想获取名称和图片 URL ..
我正在尝试这段代码..
FacebookClient client = new FacebookClient();
var friendListData = client.Get("https://graph.facebook.com/?ids=100005000000000&fields=name,picture");
JObject friendListJson = JObject.Parse(friendListData.ToString());
string json = Convert.ToString(friendListJson);
XmlDocument doc = (XmlDocument)JsonConvert.DeserializeXmlNode(json, "root");
string xml = doc.InnerXml;
XDocument myXdoc = XDocument.Load(new StringReader(xml));
var list = from loc in myXdoc.Descendants("root").Elements("100005000000000")
select new
{
//Id = loc.Element("id").Value,
Name = loc.Element("name").Value,
url=loc.Element("url").Value,
};
但是,出现错误是“名称不能以 '1' 字符开头,十六进制值 0x31。” 请改正。
<root>
<100005000000000>
<name>XXX</name>
<id>100005000000000</id>
<picture>
<data>
<url>http://profile.ak.fbcdn.net/hprofile-ak-prn2/000000_100005000000000_1666666666_q.jpg</url>
<is_silhouette>false</is_silhouette>
</data>
</picture>
</100005000000000>
</root>
这是json
{
"100005000000000": {
"name": "XXXX",
"id": "100005000000000",
"picture": {
"data": {
"url": "profile.ak.fbcdn.net/hprofile-ak-prn2/…;,
"is_silhouette": false
}
}
}
}