-6
I need to mount this json from a string and pass as parameter:
I did that:
string s = "{\"Matriz\":12, \"Filial\":21}";
At 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 you get to this line
var responeMessage = await client.PostAsync("/Service/Service.svc/GetIndicator", new StringContent("jsonValue", Encoding.UTF8, "application/json"));
the system aborts. Nor enters the catch
.
I hope with this DIT I left the original question, I think not since the goal is to mount the json correctly.
Includes your string
– Leandro Angelo
Please, if possible, improve the description of your problem, and also supplement it with what you have already done, or mistakes that are happening to help us help you.
– Grupo CDS Informática
In reality is to mount a json with this output. I have no idea how I would do with the string. If
string js="Matriz:12,Filial:21
. I have no idea what it would be like, reason for the post.– pnet
You have this data as in C#? The . net has object serializers for json.
– bfavaretto