Access a list / array in a JSON URL

3

I am sending via JSON an array of strings, how can I access this array via url? example of some of the tests:

  

link    link {carrengado, erro}

But it did not work, does anyone know how I can do this?

[HttpGet]
public HttpResponseMessage GetLanguageList(List<string> keys)
{
    try
    {
        #region meu codigo

        Dictionary<string, string> key_value = new Dictionary<string, string>();


        foreach (string key in keys)
        {
            key_value.Add(key,Resources.Language.ResourceManager.GetString(key));
        }

        #endregion

        return Request.CreateResponse(HttpStatusCode.OK, new ResponseApi()
        {
            Status = Status.OK,
            Message = "Sucesso",
            Response = key_value
        },
        "application/json");
    }
    catch (Exception ex)
    {
        return Request.CreateResponse(HttpStatusCode.OK, new ResponseApi()
        {
            Status = Status.NOK,
            Message = ex.Message,
            Response = null
        },
        "application/json");
    }
}
    
asked by anonymous 19.09.2018 / 15:16

1 answer

1

Just repeat the name of the list variable that appears on your Controller, in your case keys , when the controller receives the request it will know it is a list and will convert automatically.

http://localhost:51746/api/Language/GetLanguageList?keys=carregando&keys=erro

If you want to send JSON you will have to use the POST method, you do not send the entire object (in your case JSON) via GET .

    
19.09.2018 / 15:28