I need to mount this json from a string and pass it as a parameter:
I did this:
string s = "{\"Matriz\":12, \"Filial\":21}";
In the click of my button I have this:
private void Click_Service(object sender, EventArgs e)
{
DataService dataService = new DataService();
string jvalue = "{"\"Matriz\":12, \"Filial\":21"}";
dataService.PostIndicador(jvalue);
}
And in my service I have this:
public async Task<string> PostIndicador(string jsonValue)
{
string retorno = null;
//string jvalue = JsonConvert.SerializeObject(jsonValue);
if (NetworkCheck.IsInternet())
{
string url_base = $"meu_ip";
var uri = new Uri(string.Format(url_base));
using (var client = new HttpClient() { BaseAddress = uri })
{
var responeMessage =
await client.PostAsync("/Service/Service.svc/GetIndicator", new StringContent("jsonValue", Encoding.UTF8, "application/json"));
var resultcontent = await responeMessage.Content.ReadAsStringAsync();
retorno = (JsonConvert.DeserializeObject(resultcontent)).ToString();
}
}
return retorno;
}
The whole question is whether jsonValue
is in the correct format, because when it arrives at this line
var responeMessage = await client.PostAsync("/Service/Service.svc/GetIndicator", new StringContent("jsonValue", Encoding.UTF8, "application/json"));
The system aborts. Nor does it enter catch
.
I hope that with this edit I left the original question, I think not since the goal is to mount json correctly.