sauljabin / xmlrpcwsc-dotnet

XML-RPC Web Service Client C# implementation
GNU Lesser General Public License v3.0
34 stars 21 forks source link

To Json #3

Open budoray opened 6 years ago

budoray commented 6 years ago

It would be really helpful if XmpRpcResponse.GetString() would return as valid json. The namespace / class name is used when values are of type Dictionary<string, object> in ObjectToString(object value) and the temp.Value is a List. My current workaround is to manually parse the response.

var query = new List<string> { "name", "ilike", "fieldservice.task"};
var fields = new List<string> { "problems", "name" }; 
var list = response.GetObject() as List<object>;
var dict = list[0] as Dictionary<string, object>;
var problemIds = dict["problems"];

Perhaps a new method GetJson() would be a great enhancement?

My XmlRpcResponse.GetString() returns the following:

[{"problems": "System.Collections.Generic.List1[System.Object]", "id": "3434", "name": "Engine / Exhaust System"}]`

Another workaround, for me, would be to modify the foreach loop in the ObjectToString method to test if the temp.Value is List and insert another for loop to iterate over it to build up the desired json string. Is there another option that I am missing?

fjarboleda-lm commented 3 years ago

Hello,

I solved this issue converting the response XmlRpcResponse to a List<Dictionary<string,object>> List because Odoo could response a list and Dictionary for property value set.

With a bit of Refection and kept in mind the list of object could be only:

  • list of int by example move_ids -> [1,2,3,44 ]
  • list of a id and a name ref as company_id -> [ 18, 'IBM.t company' ]

Happy coding!