I am trying to map Array response type from an XML-RPC, but I can't understand how to do it
The documentation about XML-RPC.NET library I am using is here http://xml-rpc.net/faq/xmlrpcnetfaq-2-5-0.html
The example of response I get (int is always 0, and string contains random numbers) here:
<methodResponse>
<params>
<param>
<value>
<array>
<data>
<value>
<int>0</int>
</value>
<value>
<string>9869117656.9552</string>
</value>
</data>
</array>
</value>
</param>
</params>
</methodResponse>
Here are my attempts in C# how to collect the response data
public struct try1 {
public object[] returnstuff;
}
public struct try2
{
public int returncode;
public string token;
}
But all these throw same exception:
CookComputing.XmlRpc.XmlRpcTypeMismatchException'
Additional information: response contains array value where struct expected
Can you help me figure it out how to make correct C# structure to collect response inormation?
Try xml linq
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Xml.Linq;
namespace ConsoleApplication1
{
class Program
{
const string FILENAME = @"c:\temp\test.xml";
static void Main(string[] args)
{
XDocument doc = XDocument.Load(FILENAME);
Data data = new Data();
data.values = doc.Descendants("data").Select(x => new Values() {
returncode = (int?)x.Descendants("int").FirstOrDefault(),
token = (string)x.Descendants("string").FirstOrDefault()
}).ToArray();
}
}
public class Data
{
public Values[] values;
}
public class Values
{
public int? returncode;
public string token;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.