xmlrpcwsc-dotnet icon indicating copy to clipboard operation
xmlrpcwsc-dotnet copied to clipboard

To Json

Open budoray opened this issue 6 years ago • 1 comments

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?

budoray avatar Oct 03 '18 15:10 budoray

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!

fjarboleda-lm avatar Mar 31 '21 09:03 fjarboleda-lm