0

Newbie in this so sorry for the mistakes. I have a C# app that is running and calling python functions. the functions is being called using POST method. In addition, I would like that this call will reply from python to C# object which include 4 arrays. I successfully did passing a simple string but when I am trying to pass an object, it doesnt work. Here is the code:

C# caller side

public class RootObject
{

    public Array b1 { get; set; }
    public Array cl { get; set; }
    public Array sc { get; set; }
}
public static List<RootObject> post(string path, int Port)
{
                var client = new RestClient("http://localhost:" + 
                Port.ToString());
                var request = new RestRequest("/postmethod", Method.POST);
                request.AddHeader("content-type", "application/form-data");
                request.AddFile("file", path);
                IRestResponse response = client.Execute(request);
                var json = response.Content;
                var content = response.Content; // raw content as string

                List<RootObject> r;

                r = JsonConvert.DeserializeObject<List<RootObject>>(json);
                return r;                   
}

Python side

class myscoresobj:
def __init__(self):
    self.b1
    self.cl
    self.sc

@app.route('/postmethod', methods=['POST'])
def index():

if 'file' not in request.files:
    return "file not found"
file = request.files['file']
contents = file.read()
....
myscoresobj = worker(input_q, output_q) 

return str(myscoresobj )

Any way how to solve this?

Sagi
  • 11
  • 1
  • 3
  • Possible duplicate of https://stackoverflow.com/questions/28012335/json-net-deserializeobject-to-list-of-objects – theoretical Nov 10 '17 at 22:42
  • first check if the returned content string is indeed the correct json – Steve Nov 10 '17 at 22:53
  • Should I build a structured JSON object in Python to be sent? myscoresobj is just a standard class? If I send this object I get j'son = ""' 'content = ""' – Sagi Nov 11 '17 at 07:12

0 Answers0