I have a function which sends a Vector3 pos to a robot via RestSharp and the response of the POST call looks like this:
{present_effector_pos: true/false}
I want to parse the true or false and return it as boolean.
public bool postEffectroPos(Vector3 pos, float speed_n)
{
var client = new RestClient("http://"+robotIP);
var request = new RestRequest("/present/effector_position_with_speed.json", Method.POST) { RequestFormat = RestSharp.DataFormat.Json };
effectorPos a = new effectorPos();
a.x = pos.x;
a.y = pos.z;
a.z = pos.y;
a.speed = speed_n;
request.AddBody(a);
bool move = false;
try
{
client.ExecuteAsync(request, response =>
{
if (response.StatusCode == HttpStatusCode.OK)
{
string[] tmp = response.Content.Split(':');
string t = tmp[1].Remove(tmp[1].Length - 1);
move = bool.Parse(t);
Debug.Log(move);
}
else
{
Debug.Log(response.StatusCode);
}
});
}
catch (Exception error)
{
Debug.Log(error);
}
return move;
}
But no matter to what value the variable move
is changed in the if clause through parsing the method always returns false
.